这看起来很简单,但并不像预期的那样起作用:
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;我希望结果会有一个观察结果
约翰·雅各布·金尔海默·施密特
但namelist只是John。我做错了什么?
发布于 2012-10-03 18:17:49
在连接到列表之前,您需要调整空格。
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;您还可以使用cat()函数(它为您进行修整和连接):
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-03 19:12:12
如果你在你的任务中加入了脱衣舞
strip(namelist) || "|" || name它也会起作用
(但猫是一个很好的解决方案)
发布于 2012-10-04 08:46:47
使用catx函数可以指定分隔符.
data names;
length namelist $100.;
set names end=eof;
retain namelist;
namelist = catx("|",namelist,name);
if eof then output;
run;https://stackoverflow.com/questions/12714302
复制相似问题