全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
2381 8
2013-10-14
悬赏 10 个论坛币 已解决
各位大神大牛,我有5个字段的学生数据,包括:学生姓名,学号,性别,入学日期,毕业日期。

可是有100个班的TXT文件,文件名分别是:1班,2班,3班...100班,


想要将他们合并,同时导入sas进行分析,求助各位大侠写个宏程序一次性批量导入,感激不尽啊

最佳答案

yongyitian 查看完整内容

The following code requires that the filenames has the form: class1.txt class2.txt ... class100.txt, and the variables are in the order: Name ID Gender Edate Bdate. If there is no variable names in the text file, the firstobs=1 should be used.
二维码

扫码加我 拉你入群

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

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

全部回复
2013-10-14 01:07:04
The following code requires that the filenames has the form: class1.txt class2.txt ... class100.txt, and the variables are in the order: Name ID Gender Edate Bdate.
If there is no variable names in the text file, the firstobs=1 should be used.
复制代码
二维码

扫码加我 拉你入群

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

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

2013-10-14 10:04:06
%macro merge(num);
  proc printto log=_null_;
  %do i=1 %to #
    proc import out=class&i datafile="c:\docs\class&i.txt" dbms=dlm replace;
    %if i=1 %then %do;
           data class_all;
            set class&i(obs=0);
           run;
        %end;
        proc append base=class_all data=class&i;
        proc datasets lib=work nolist;
    delete class&i;
        run;
  %end;
  proc printto;
  run;
%mend;

%merge(100)
二维码

扫码加我 拉你入群

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

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

2013-10-14 11:38:05
farmman60 发表于 2013-10-14 10:04
%macro merge(num);
  proc printto log=_null_;
  %do i=1 %to #
复制代码
这句是干什么?还有obs=0起什么作用?
二维码

扫码加我 拉你入群

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

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

2013-10-14 13:22:25
不同表内的数据需要flag吗?
二维码

扫码加我 拉你入群

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

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

2013-10-14 15:28:58
复制代码
假设文件都在TEMP文件夹下
二维码

扫码加我 拉你入群

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

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

点击查看更多内容…
相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

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