如何将国家划分为SAS中的数据,如:
country city
United States Seattle
United Kingdom London发布于 2013-12-10 21:49:16
使用以逗号为分隔符的函数扫描()。
data test;
set test;
city=scan(country,2,',');
country=scan(country,1,',');
run;发布于 2013-12-10 22:01:17
另一种选择是INFILE magic (google是关于这个主题的论文的术语);用于解析一个字符串中的许多变量和/或处理引用的字段,这将是scan的更多工作。
filename tempfile "c:\temp\test.txt";
data have;
input @1 country $50.;
datalines;
United States, Seattle
United Kingdom, London
;;;;
run;
data want;
set have;
infile tempfile dlm=',' dsd;
input @1 @@;
_infile_=country;
format newcountry city $50.;
input newcountry $ city $ @@;
run;tempfile可以是任何文件(也可以是动态创建的文件,其中包含任何字符,以避免过早的EOF)。
发布于 2022-04-21 06:17:59
答复:
data test;
set test;
city=scan(country,2,',');
country=scan(country,1,',');
run;如果我只想在字符串中拆分最后一个逗号,保留7410 City怎么办?
例子:“少年18岁,钢琴演奏,7410城
https://stackoverflow.com/questions/20505871
复制相似问题