BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
hhchenfx
Barite | Level 11

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;
1 ACCEPTED SOLUTION

Accepted Solutions
hhchenfx
Barite | Level 11

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;

View solution in original post

1 REPLY 1
hhchenfx
Barite | Level 11

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;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 1139 views
  • 0 likes
  • 1 in conversation