質問

私は以下に定義される関数を経由し,FCMP.のポイントコードすることは非常にわかり、比較的簡単です。私は帰属性の値からラインのユーザー設定値の初期化.こちらのコード:

proc fcmp outlib=library.funcs.crawl;
    function getAttr(htmline $, Attribute $) $;

       /*-- Find the position of the match --*/
    Pos = index( htmline , strip( Attribute )||"=" );

       /*-- Now do something about it --*/
       if pos > 0 then do;
          Value = scan( substr( htmline, Pos + length( Attribute ) + 2), 1, '"');
       end;
       else Value = "";
       return( Value);
    endsub;
run;

どんな特別口座の口座管理機関の長さはattrib決して明示的に宣言するデータ型を返す返しますみの最大数を33バイトの求めの文字列を問わずかに長く、実際の戻り値です。このいずれの属性で昼間のお仕事をお持ちです。同じコード(ハードコーディング)データをステップを返します正しい結果では,FCMP.

こちらはdatastepを使用している試験であPageSource.html はhtmlファイルがxhtml準拠の属性--完全に引用):

data TEST;
length href $200;
infile "F:\PageSource.html";

input;

htmline = _INFILE_;

href = getAttr( htmline, "href");
x = length(href);

run;

更新:このように正しく動作後にアップグレードSAS9.2リリース2

役に立ちましたか?

解決 3

当社がバックを利用して行われた行FCMP定義データをステップで機能する。とは思わないい準備をprimetime.い表せない貴重な経験になりの解決を33バイトを返しの問題ですが、定期的に開始しぶSAS.

ので、良いものか、何十年も古い技術のマクロです。この作品:

/*********************************/
/*= Macro to extract Attribute  =*/
/*= from XHTML string           =*/
/*********************************/
%macro getAttr( htmline, Attribute, NewVar );
   if index( &htmline , strip( &Attribute )||"=" ) > 0 then do;
      &NewVar = scan( substr( &htmline, index( &htmline , strip( &Attribute )||"=" ) + length( &Attribute ) + 2), 1, '"' );
   end;
%mend;

他のヒント

この場合、入力ポインタの管理は十分です。武器agiは、dexで下がらないboxerぐ.

/* create a test input file */
data _null_;
  file "f:\pageSource.html";
  input;
  put _infile_;
cards4;
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="w3.org/StyleSheets/TR/W3C-REC.css"; type="text/css"?>
;;;;
run;

/* extract the href attribute value, if any.                          */
/* assuming that the value and the attribute name occurs in one line. */
/* and max length is 200 chars.                                       */
data one;
  infile "f:\pageSource.html" missover;
  input @("href=") href :$200.;
  href = scan(href, 1, '"'); /* unquote */
run;

/* check */
proc print data=one;
run;
/* on lst
Obs                  href
 1
 2     w3.org/StyleSheets/TR/W3C-REC.css
*/

と思い、問題がなぜだかよくわかりません)は、スキャン機能で切り捨入力からのsubstr().きのsubstr機能のスキャン()を割り当て,結果のsubstrの機能を変数としてパススキャンするようです。

ここには何を行った:

proc fcmp outlib=work.funcs.crawl;
    function getAttr(htmline $, Attribute $) $;
    length y $200;
       /*-- Find the position of the match --*/
    Pos = index( htmline , strip( Attribute )||"=" );

       /*-- Now do something about it --*/
       if pos > 0 then do;
          y=substr( htmline, Pos + length( Attribute ) + 2);
          Value = scan( y, 1, '"');       
       end;
       else Value = "";
       return( Value);
    endsub;
run;

options cmplib=work.funcs;

data TEST;
length href $200;
infile "PageSource.html";

input;

htmline = _INFILE_;
href = getAttr( htmline, "href");
x = length(href);
run;
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top