全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
2210 5
2012-06-21
- .TXT文件m列(tab分隔),n+1行,第一行全为CHAR(将作为目标dataset中的变量名),之后的n行将作为目标dataset中的记录.
- m和n的值是变化的(以适应不同的TXT文件).
THANK YOU ALL!
二维码

扫码加我 拉你入群

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

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

全部回复
2012-6-21 09:41:03
补充: TXT文件中第一行各值为字符(无规律),但符合SAS变量名规则.
如:
A_B    XY    CQ     MN_T
7        acb    12     cdf
9        xyc    23     xys
66       tttt    12     uuu
.....
....
....
二维码

扫码加我 拉你入群

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

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

2012-6-23 10:04:42
期待能人.....
二维码

扫码加我 拉你入群

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

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

2012-6-23 15:34:24
复制代码
options noxwait noxsync mlogic mprint;

x"dir dir D:\path\*.txt /b >d:\path.txt";

%macro a();
  data temp1;
    length x $50
           fname $50;
    infile"d:\path.txt";
    input x $;
    fname="D:\path\"||trim(left(x));
  run;

  data _null_;
    set temp1 end=last;
    call symputx("fname"||trim(left(_n_)),fname);
    if last then do;
      call symputx("nobs1",_n_);
    end;
  run;

  %do i=1 %to &nobs1.;

    data temp;
      length %do j1=1 %to 1000; x&j1 $20 %end;;
      infile"&&fname&i" dlm='09'x obs=1 missover ;
      input  %do j2=1 %to 1000; x&j2 $ %end;;
    run;


    data _null_;
      set temp;
      %do j3=1 %to 10;
        call symputx("var_name_"||"&j3",x&j3);
      %end;
    run;
       
    data data_&i.;
       %do j4=1 %to 1000; %if &&var_name_&j4.^=  %then %do; length &&var_name_&j4.  $20 ; %end;%end;;
      infile"&&fname&i" dlm='09'x  missover firstobs=2;
      input %do j5=1 %to 1000; %if &&var_name_&j5.^=  %then %do ;  &&var_name_&j5.  $  %end;%end;;
    run;

   %end;

  %mend;
  %a();
二维码

扫码加我 拉你入群

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

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

2012-6-23 15:36:37
还有,创建的data set我都放在了work库里面,data名称也是随意的
二维码

扫码加我 拉你入群

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

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

2012-6-24 00:46:04
! 谢谢啦! 复制回去好好学习研究.
二维码

扫码加我 拉你入群

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

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

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

说点什么

分享

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