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) ;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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