t********m 发帖数: 939 | 1 如果我在一个文件夹下面有很多的sas data set,现在我想将它们全部转换成stata
data set,怎样方便快捷呢?我能想到的是写一个macro,但是文件名还是得一个一个
输,请教各位大牛,有没有什么办法能自动get到所有文件,然后转换后的文件default
就用原来的文件名?谢谢!
%macro convert(name);
proc export data=lib.&name
outfile="D:\work\&name..dta"
dbms=stata replace;
run;
%mend convert;
%convert(name1);
%convert(name2);
%convert(name3);
...... | P**********c 发帖数: 17 | 2 一种方法:
你的文件名没有规律
%macro convert (infilelist=);
%let i=1;
%let infile=%scan(&infilelist,&i);
%do %while ("&infile"~="");
proc export data=temp.&infile
outfile="c:\temp\&infile..dta"
dbms=stata replace;
run;
%let i=%eval(&i+1);
%let infile=%scan(&infilelist,&i);
%end;
%mend convert;
%convert(infilelist=name1 name2 name3 ...);
二种方法:
如果你的文件名有规律,例如 name1 name2 name3 name4 ... name20
你可以再写一个macro,调用你自己写的convert macro
%macro out_to_stata;
%do i =1 %to 20;
%convert(name&i);
%end;
%macro out_to_stata;
%out_to_stata; | s*********e 发帖数: 1051 | 3 for your first solution, you need to use pipe to obtain the list of file
names. otherwise, it is not generic.
【在 P**********c 的大作中提到】![](/moin_static193/solenoid/img/up.png) : 一种方法: : 你的文件名没有规律 : %macro convert (infilelist=); : %let i=1; : %let infile=%scan(&infilelist,&i); : %do %while ("&infile"~=""); : proc export data=temp.&infile : outfile="c:\temp\&infile..dta" : dbms=stata replace; : run;
| j*****7 发帖数: 4348 | 4 libname test "X:\XXX\XXX\XXX";
proc sql noprint;
create table ddfdata as
select memname as dataset label='Data Set Name',
name as variable label='Variable Name',
label label='Variable Label',
type label='Variable Type',
count (distinct memname) into :totmem
from sashelp.vcolumn where libname='TEST'
order by dataset,name;
quit;
%macro trans;
data _null_;
set ddfdata;
by dataset notsorted;
retain b 1;
if first.dataset then do;
call symput(compress(trim(left('member'||trim(left(b)) ))),compress(trim(
left(dataset))));
call symput('totmem',put(b,2.));
b=b+1;
end;
run;
%put &totmem;
%do b = 1 %to &totmem;
proc export data=test.&&member&b
outfile="X:\XXX\XXX\XXX\stata\&&member&b..dta"
dbms=stata replace;
run;
%end ;
%mend trans ;
%trans; |
|