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

I have created a macro called: num_obs that returns the number of observations in a data set. 

I can save the result in an data step like: 

data saved_num_obs; 
	observ = %num_obs(WORK.TEST); 
run; 


Now, I would like to save the result to a macro variable instead. 

So, how would i save an result from using a macro to a Macro variable? 

I thought something like: 

%let My_Macro = num_obs(test_table) ; 

This does not work. 

Any suggestions? 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

If depends a lot on how the macro works.

But first make sure to actually call the macro and not just assign the name of the macro to the macro variable.  You left the % out of your macro call.

%let My_Macro = %num_obs(test_table) ;

View solution in original post

2 REPLIES 2
andreas_lds
Jade | Level 19

Just call the macro the same way you use in the data step: with leading %.

Tom
Super User Tom
Super User

If depends a lot on how the macro works.

But first make sure to actually call the macro and not just assign the name of the macro to the macro variable.  You left the % out of your macro call.

%let My_Macro = %num_obs(test_table) ;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 544 views
  • 2 likes
  • 3 in conversation