全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
1912 4
2008-03-20

用sas如何读下列格式的数据;(冒号后是相应的值)

y:34 x1:243 x2:43 x3:56 x4:65

y:24 x1:645 x3:55 x4:56(有缺失数据)

.........

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2008-3-21 04:57:00

 read as char frist and use substr + input to get the number you want

[此贴子已经被作者于2008-3-21 5:24:15编辑过]

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2008-3-21 05:58:00
data ds;
array xx {5} $ xx1-xx5  ;
infile "c:\datafile.txt" missover;
input xx1-xx5  ;
run;


data datset;
array x{0:4}  x0-x4;
array xx{5} $  xx1-xx5;
set ds;
    do i=1 to 5;
            if xx(i)="" then x(i-1)="" ;
                 else
                    select (substr(xx(i),1,2));
                        when ('y:') x(i-1)=substr (xx(i),3,0);
                        when ('x1') x(i-1)=substr (xx(i),4,0);
                        when ('x2') x(i-1)=substr (xx(i),4,0);
                        when ('x3') x(i-1)=substr (xx(i),4,0);
                        when ('x4') x(i-1)=substr (xx(i),4,0);
                        when ('x5') x(i-1)=substr (xx(i),4,0);
                        otherwise;
                    end;
    
    end;

drop xx1-xx5  i;
rename x0=y;
run;
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2008-3-22 00:11:00

谢谢

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2008-3-22 00:17:00

不过,可能还会有问题。

它们之间可能没有空格:y:45x1:456...

这样也能区分数据.要是出现这种情况还有法读吗?

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群