|
|
Re: 变量名称数值时,如何实现导入?
在宏里面怎么应用tab分隔符,我还真想不出办法来。希望大家可以帮助一起来探讨。
现在我只能换种不伦不类的方法解决你的tab问题
[code:1no6oms5]
/*以TAB为分隔符的txt文件,file为文件,out为导入后生成的数据集,prefix为变量名前缀*/
%macro a(file,out,prefix,dlm);
proc import datafile="&file" out=&out dbms=dlm replace;
delimiter='09'x;
getnames=no;
datarow=2;
run;
data _null_;
infile "&file" lrecl=32767 _infile_=a firstobs=1 obs=1;
input;
call symputx('var',a);
run;
%let dsid=%sysfunc(open(&out));
%let nvar=%sysfunc(attrn(&dsid,nvars));
%let rename=rename;
%do i=1 %to &nvar;
%let oldName=%sysfunc(varname(&dsid,&i));
%let newName=%scan(&var,&i);
%let rename=%str(&rename &oldName=&preFix&newName);
%end;
%let rc=%sysfunc(close(&dsid));
%let strLib=%scan(&out,1,%str(.));
%let strTable=%scan(&out,2,%str(.));
%if &strTable= %then %do;
%let strTable=&strLib;
%let strLib=WORK;
%end;
proc datasets lib=&strLib nolist memtype=data;
modify &strTable;
&rename;
quit;
%mend;
%a(c:\test.txt,result,_);
[/code:1no6oms5] |
|