0

我有一个像这样的原始数据文件:

JamesBrownSenior
AshleyPinkJunior

第一列是名称。第二个是颜色标签。.. 但是对于每一列,观察长度各不相同。

我试过这个

data ct_11;
 infile '';
 length Name $ 10 Tag $ 10 Title $ 10;
 input Name $ Tag $ Title $;
run;

它没有用。我想我错过了一些选择。

4

1 回答 1

1

If there is no delimiter you have to read it as a single variable and then split it afterwards based on a rule. In your case tou can add a delimiter using a regular expression and then use the scan function to write the words to different variables.

data ct_11 (keep=name tag title);
 infile 'z:\nametagtitle.txt';
 length line $120 name tag title $40;
 input line $;
 dlmline = prxchange('s/([A-Z]{1}[a-z]*)([A-Z]{1}[a-z]*)([A-Z]{1}[a-z]*)/$1 $2 $3/',-1,line);
 name = scan(dlmLine,1);
 tag = scan(dlmline,2);
 title = scan(dlmline,3);
run;
于 2013-10-10T08:58:19.013 回答