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-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
  • 2 replies
  • 699 views
  • 0 likes
  • 3 in conversation