Hi Everyone,
I have 2 files: entry file and Master file.
I want to take subsample from Master file that meet each condition in entry file to further analyze.
(it is a bit like proc SQL to get subsample but the analysis is complicate that I can create that big file using proc SQL).
So my solution is that:
Step 1: start from entry file, work with the 1st record, a and 1.
Step 2: I go to mater file and select all records that meet condition in step 1, or records with a =1 --> 2 record
analyze that subsample.
after I am done
Go back to step 1: work on 2nd record
I vision my code has 2 macro;
Outer macro that run throught entry file
Inner macro that pick record from master and process
I want to run from the beginning to the end of the entry file but I dont know how to do
it.
Could you please help me?
Thank you so much for your help.
HC
data entry;
input variable $ value;
datalines;
a 1
a 2
b 6
b 9
;run;
data masterfile;
input a b c d;
datalines;
1 2 3 4
1 9 3 2
2 9 2 3
;
run;
*the first record in entry file;
data _entry_temp; set entry;
if _N_=1;
run;
*create macro value to feed the inner macro;
proc sql noprint; select variable into: entry_name from _entry_temp; quit;
proc sql noprint; select value into : entry_value from _entry_temp; quit;
*Use the above to 2 value to feed inner Macro in a seperate file
for checking purpose, I just want to create new file with macro name;
%macro inner(entry_name2 = ,entry_value2=);
data want_&entry_name.&entry_value; set _entry_temp;
run;
%mend;
oh, I got it. Not perfect but get the job done.
a quick question: why this one doesnt work?
data want_&entry_name&entry_value; set _entry_temp;run;
data entry;
input variable $ value;
datalines;
a 1
a 2
b 6
b 9
;run;
proc sql noprint;
select count(*) into: nobs from entry;quit;
%put &nobs;
data masterfile;
input a b c d;
datalines;
1 2 3 4
1 9 3 2
2 9 2 3
;
run;
%MACRO SINGLE_FACTOR;
%DO ENTRY_COUNT=1 %TO &NOBS;
%PUT "NEW ROUND";
%put &ENTRY_COUNT;
*the first record in entry file;
data _entry_temp; set entry;
if _N_=&ENTRY_COUNT;
run;
*create macro value to feed the inner macro;
proc sql noprint; select variable into: entry_name from _entry_temp; quit;
proc sql noprint; select value into : entry_value from _entry_temp; quit;
%put &entry_name;run;
%put &entry_value;run;
*Use the above to 2 value to feed inner Macro in a seperate file
for checking purpose, I just want to create new file with macro name;
data want; set masterfile;
IF &entry_name=&entry_value;
run;
%END;
%MEND;
%SINGLE_FACTOR;
oh, I got it. Not perfect but get the job done.
a quick question: why this one doesnt work?
data want_&entry_name&entry_value; set _entry_temp;run;
data entry;
input variable $ value;
datalines;
a 1
a 2
b 6
b 9
;run;
proc sql noprint;
select count(*) into: nobs from entry;quit;
%put &nobs;
data masterfile;
input a b c d;
datalines;
1 2 3 4
1 9 3 2
2 9 2 3
;
run;
%MACRO SINGLE_FACTOR;
%DO ENTRY_COUNT=1 %TO &NOBS;
%PUT "NEW ROUND";
%put &ENTRY_COUNT;
*the first record in entry file;
data _entry_temp; set entry;
if _N_=&ENTRY_COUNT;
run;
*create macro value to feed the inner macro;
proc sql noprint; select variable into: entry_name from _entry_temp; quit;
proc sql noprint; select value into : entry_value from _entry_temp; quit;
%put &entry_name;run;
%put &entry_value;run;
*Use the above to 2 value to feed inner Macro in a seperate file
for checking purpose, I just want to create new file with macro name;
data want; set masterfile;
IF &entry_name=&entry_value;
run;
%END;
%MEND;
%SINGLE_FACTOR;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.