BookmarkSubscribeRSS Feed
pja77
Calcite | Level 5

I'm Using Base SAS 9.4 TM5 on a Windows 7 Desktop.

 

I'm trying to run a data step that utilizes a Call Execute Statement that runs a macro given the parameters from the observation in the data step and takes the Macro Variables from the Call Execute Statement and saves it as a data set variables to the current data set where Rx_Fill_Date is. See an excerpt from the code

 

data PMP_all_temp;

--- additional code up here ---

CALL EXECUTE('%MDSLkup(ID='||TRIM(LEFT(Subj_ID_file))||',Date='||Rx_Fill_Date||');');
	
	MAT_DoseStatus = SYMGET('MAT_DoseStatus');
	MAT_Dose = SYMGET('MAT_Dose');
	MAT_THB = SYMGET('MAT_THB');
	MAT_Phase = SYMGET('MAT_Phase');
	MAT_Epicount = SYMGET('MAT_Epicount');
	MAT_EpiStatus = SYMGET('MAT_EpiStatus');
	MAT_Admit1 = SYMGET('MAT_Admit1');
	MAT_Discharge1 = SYMGET('MAT_Discharge1');
	MAT_Admit2 = SYMGET('MAT_Admit2');
	MAT_Discharge2 = SYMGET('MAT_Discharge2'); 

drop pos;
run

The Macro in question is essentially a lookup macro where it looks up the Date and Subject_ID and returns the data that is stored for that date from a larger dataset of about 20,000 variables.

 

%MACRO MSDLkup(ID=,Date=);

Lookup_ID = "&ID.";
Lookup_Date = &date.;

---- ARRAY Declaration Statements and other necessary code -----

nvalues_epi = N(of Episodes_DateAdmit1-Episodes_DateAdmit10);

if Subj_ID = Lookup_ID then do;
		do i = 1 to 5000;
			if Days[i] = Lookup_Date then do;
				CALL SYMPUTX('MAT_DoseStatus',"Dosing Record Exist","G");
				CALL SYMPUTX('MAT_Dose',Dose[i],"G");
				CALL SYMPUTX('MAT_THB',THB[i],"G");
				CALL SYMPUTX('MAT_Phase',P[i],"G");
				CALL SYMPUTX('MAT_EpiCount',EpiCount[i],"G");
				DoseOutput = 1;
			end;
		end;
		if DoseOutput = . THEN DO;
				CALL SYMPUTX('MAT_DoseStatus',"Dosing Record DOES NOT Exist for Date");
				CALL SYMPUTX('MAT_Dose',"N/A","G");
				CALL SYMPUTX('MAT_THB',"N/A","G");
				CALL SYMPUTX('MAT_Phase',"N/A","G");
				CALL SYMPUTX('MAT_EpiCount',"N/A","G");
				DoseOutput = 1;
		END;

The problem that I'm having is that while the Call Execute is running correctly and correctly inputting the 7 Character Subject ID and the Date for each observation in the Macro as for each observation as evidented in my Log and a print out showing that a successful lookup was done for the first observation,

SAS Communities Screenshot of NJPMP Code.png

the Macro Variables are not being overwritten for each iteration of the Call Execute statement, and thus the PROC Print of this dataset shows the same data for the first observation for all subsequent observations. How can I set up my Macro Variable to be overwritten so each iteration of call execute in each observation displays the unique data based on date and subject.

 

Thank you!

 

 

 

2 REPLIES 2
Kurt_Bremser
Super User

Call execute pushes code into the execution queue, for execution once the calling data step has ended. So anything created by that code can't ever be available in the calling data step.

 

If you need a lookup done, use a hash object.

smantha
Lapis Lazuli | Level 10

I would like to point out few things in the code:

1. As @Kurt_Bremser pointed out call execute are put on a queue for execution and are executed after the datastep is done. Hence the reason you cannot use symput and sympget in the same datastep in your case.

2. I do not understand the objective of your program if call execute is overriding the macro variable being created and you get the value. If you are trying to get the values for display purpose you might as well say put inside your code. Why not do a join on the two datasets by ID and Date and get the variables you want by executing the code you shared with is in the macro.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 2 replies
  • 471 views
  • 2 likes
  • 3 in conversation