Hi,
I have a question about saving more than 1 macro variables at the same time. I have 80 files merged_1, merged_2,....., merged_80. I want to count how many observations for each file, and save the number for each file for further use. Thank you in advance for your help!
If I have only 1 file merged_1, I will write codes as below and it works.
proc sql;
select count(student_id) into: obs_num
from merged_1;
quit;
%put &obs_num.;
Now I have 80 files. I tried the following codes, but it does not work.
%macro boots;
%do i = 1 %to 80;
proc sql;
select count(student_id) into: obs_num_&i
from merged_&i;
quit;
%put &obs_num_&i;
%end;
%mend;
%boots;
Thanks, Astounding! That works.
I have a follow up question about how to use that macro variable. Thank you in advance for your answer!
I want to use bootstrap to run 1,000 times with replacement for each of 80 files. The count of observation for each file is different, saved in that macro variable &&obs_num_&i. So basically, for example, if merge_1 has 200 obs, then I want to create 1000 files, each of which has 200 obs, sampled from merge_1 with replacement. (My final target is to calculate mean and s.d. for each of 1000 files per each of 80 files. This part does not include in the following code.)
My code is shown below. It has error for the macro variable &&obs_num_&i. The error shows below as an example for each of variables generated.
------
50 &obs_num_1
_
22
WARNING: Apparent symbolic reference OBS_NUM_1 not resolved.
ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, a numeric constant, a datetime constant,
2 The SAS System 14:01 Tuesday, August 23, 2016
a missing value, INPUT, PUT.
------
%macro boots2;
%do i = 1 %to 2; /*will change 2 to 80*/
%do j = 1 %to 3; /*will change 3 to 1000*/
data select_&i._&j;
do sel = 1 to &&obs_num_&i;
rn = ranuni(&j. * 100000 + 20151102);
id = round(rn * 100000);
output;
end;
keep id;
run;
proc sort data=select_&i._&j;
by id;
run;
data merged_fnl_&i._&j;
merge merged_&i(in=a) select_&i._&j(in=b);
by id;
if b;
run;
%end;
%end;
%mend;
%boots2;
... View more