BookmarkSubscribeRSS Feed
manya92
Fluorite | Level 6

 

hi all, 

 

I wanted to ask how can edit this code to run without error 

%macro count_pt ;

	proc sql;
		select count(distinct patient_id), count (*) 
			into:patients trimmed into:obs
		from  &syslast. ;
	quit ;
	
	%put There are &patients. and &obs. from &syslast. ; 
	
%mend count_pt ;
%count_pt;

 

2 REPLIES 2
Astounding
PROC Star

You should be able to reorganize one line:

 

into : patients trimmed, : obs

ballardw
Super User

@manya92 wrote:

 

hi all, 

 

I wanted to ask how can edit this code to run without error 

%macro count_pt ;

	proc sql;
		select count(distinct patient_id), count (*) 
			into:patients trimmed into:obs
		from  &syslast. ;
	quit ;
	
	%put There are &patients. and &obs. from &syslast. ; 
	
%mend count_pt ;
%count_pt;

 


I would be very hesitant to say a macro that relies on referencing the last created data set for input and mentioning specific variables could ever be made to run "without errors" without providing code to check that the variables used exist in the data set. At which point you may need to have some code outside of this macro to modify following code behavior when the &syslast data set does not contain the patient_id variable.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 869 views
  • 0 likes
  • 3 in conversation