s********l 发帖数: 245 | 1 I meet a problem during the work.
I have 100 data sets need to read into SAS, such as:
data1
1 2 3 4
data2
2 3 4 8
......
data100
2 4 8 9
I want to read these 100 data to SAS and merge that to one data set,what
kind of macro I should write? Many thanks. |
s********l 发帖数: 245 | 2 The code I wrote is:
%macro data(num);
%do i=0 %to #
data est#
infile "path\data&num";
input a b c d;
run;
proc append base=data1 data=est#
run;
%mend;
%data(num=100);
through above program, I just got data combine with the data1 and the
data100. What's wrong with my program? I really need help from you! Many
thanks. |
h***i 发帖数: 634 | 3 try force option in PROC APPEND
What warning did you get in log?
【在 s********l 的大作中提到】 : The code I wrote is: : %macro data(num); : %do i=0 %to # : data est# : infile "path\data&num"; : input a b c d; : run; : proc append base=data1 data=est# : run; : %mend;
|
s*r 发帖数: 2757 | 4 &i or &num
【在 s********l 的大作中提到】 : The code I wrote is: : %macro data(num); : %do i=0 %to # : data est# : infile "path\data&num"; : input a b c d; : run; : proc append base=data1 data=est# : run; : %mend;
|
s********l 发帖数: 245 | 5 what do you mean by &i and &num? Define both of as macro variables? Many
thanks. |
x**m 发帖数: 941 | 6 I think your code failed to create the transit dataset, which is the
combination from data1 to data100 every loop.
BTW, where is the 'end;" ? Do I misunderstand sth here? |
D******n 发帖数: 2836 | 7 stare at these two lines for at least 2 mins, and you will know. |
o******6 发帖数: 538 | 8 %macro combined(total);
data a;
set %do i=1 %to &total; data&i %end;;
run;
%mend;
%combined(100)
【在 s********l 的大作中提到】 : I meet a problem during the work. : I have 100 data sets need to read into SAS, such as: : data1 : 1 2 3 4 : data2 : 2 3 4 8 : ...... : data100 : 2 4 8 9 : I want to read these 100 data to SAS and merge that to one data set,what
|
s********l 发帖数: 245 | 9 many thanks, but the data set is not SAS data, it is txt data, so I could
not use set to read it directly. |
o****o 发帖数: 8077 | 10 if by 'merge' in your OP, you meant concatenation, then you can do similar
things like below:
data _null_;
file '/UNIX/oloolo/test1.txt';
x1=1; x2=2; x3=3; x4=4;
put x1 x2 x3 x4;
file '/UNIX/oloolo/test2.txt';
x1=11; x2=12; x3=13; x4=14;
put x1 x2 x3 x4;
run;
data new;
infile '/UNIX/oloolo/test1.txt';
input x1-x4; output;
infile '/UNIX/oloolo/test2.txt';
input x1-x4; output;
run;
use a macro to wrap all files
if it is merge then the case is a
【在 s********l 的大作中提到】 : many thanks, but the data set is not SAS data, it is txt data, so I could : not use set to read it directly.
|
|
|
o******6 发帖数: 538 | 11 %macro data(num);
%do i=1 %to #
data est&i;
infile "path\data&i";
input a b c d;
run;
proc append base=newdata data=est&i force;
run;
%end;
%mend;
%data(num=100);
【在 s********l 的大作中提到】 : The code I wrote is: : %macro data(num); : %do i=0 %to # : data est# : infile "path\data&num"; : input a b c d; : run; : proc append base=data1 data=est# : run; : %mend;
|
s********l 发帖数: 245 | 12 I used the above program, but the problem is that it just run once not 100
times. |
s********l 发帖数: 245 | 13 The reason behind that I have figured out, since I assign macro variable num
=100 then when I revoke the macro est, the following infile "path\data100
will execute. |
o******6 发帖数: 538 | 14 %macro new(num);
filename combine (%do i=1 %to #"path\data&i..txt" %end;);
data newdata;
infile combine;
input a b c d;
run;
%mend;
%new(100);
num
【在 s********l 的大作中提到】 : The reason behind that I have figured out, since I assign macro variable num : =100 then when I revoke the macro est, the following infile "path\data100 : will execute.
|
Y****a 发帖数: 243 | 15 在你的%do loop里没有&i什么事吗
把loop里所有的&num改成&i试试吧
这也是 sir 的意思
另外,为什么用append,不用set?
【在 s********l 的大作中提到】 : The code I wrote is: : %macro data(num); : %do i=0 %to # : data est# : infile "path\data&num"; : input a b c d; : run; : proc append base=data1 data=est# : run; : %mend;
|