3

これは簡単に思えますが、期待どおりに機能していません。

data names;
    input name $12.;
    cards;
John
Jacob
Jingleheimer
Schmidt
;
run;

data names;
    length namelist $100.;
    set names end=eof;
    retain namelist;
    if _n_=1 then namelist=name;
    else namelist = namelist || "|" || name;
    if eof then output;
run;

結果には、次のような1つの観測値が含まれると思います。

ジョン|ジェイコブ|ジングルハイマー|シュミット

しかしnamelist、ただJohnです。私は何が間違っているのですか?

4

3 に答える 3

5

リストに連結する前に、空白を削除する必要があります。

data names;
    length namelist $100.;
    set names end=eof;
    retain namelist;
    if _n_=1 then namelist=trim(name);
    else namelist = trim(namelist) || "|" || trim(name);
    if eof then output;
run;

cats()関数(トリミングと連結を行う)を使用することもできます。

data names;
    length namelist $100.;
    set names end=eof;
    retain namelist;
    if _n_=1 then namelist=name;
    else namelist = cats(namelist,"|",name);
    if eof then output;
run;
于 2012-10-03T18:17:49.907 に答える
0

割り当てにSTRIPを追加した場合

strip(namelist) || "|" || name

それも機能します

(しかし、CATSは本当に良い解決策です)

于 2012-10-03T19:12:12.810 に答える
0

catx関数を使用すると、区切り文字を指定できます...

data names;
    length namelist $100.;
    set names end=eof;
    retain namelist;
    namelist = catx("|",namelist,name);
    if eof then output;
run;
于 2012-10-04T08:46:47.943 に答える