BookmarkSubscribeRSS Feed
JamesPatton01
Calcite | Level 5

Hello SAS Communities! 

 

I am new to macro programming and need some help in creating a macro program. Any help will be appreciated! I am wanting to create a macro program named 'GraphStats' which may be used to summarise a numeric variable from any data set. 

 

The macro should be able to generate 2 pieces of output (i.e. the macro should contain 2 steps): 

1. A histogram with PROC SGPLOT 

2. Summary statistics with PROC SUMMARY 

 

The macro should also contain the following 4 parameters:

1. ‘DSName’ to specify the data set name

2. ‘Vbl’ to specify the numeric variable

3. ‘Stats’ to specify summary statistics. Include the defaults statistics of N, MEAN, and STDEV

4. ‘NDec’ to specify the number of decimals. Include a default value of 1 

 

Thank you, 

- James 

3 REPLIES 3
Tom
Super User Tom
Super User

You have all the information you need to write the %MACRO statement that begins the definition of the macro.

But to actually write the macro you need to first produce working PROC SGPLOT and PROC SUMMARY statements. First write the code without and macro definition or macro variables. Then you can think about how to convert it into a macro.

 

Hint if you want PROC SUMMARY to produce output you need to add the PRINT option. At which point you should have just called it by its other name of PROC MEANS where the PRINT option is on by default.

Cynthia_sas
Diamond | Level 26
Hi: This paper, entitled Macro Basics for New SAS Users https://support.sas.com/resources/papers/proceedings13/120-2013.pdf shows you the entire process you need to go through to write your macro program. The key is to start with a working SAS program.
Cynthia
PaigeMiller
Diamond | Level 26

I agree that the advice given above is sound. You have to create working SAS code for one such variable from one such data set, without macros and without macro variables, before you can write a macro. If you don't have working SAS code without macros and without macro variables, then you will never achieve a working macro.


So show us the working SAS code with no macros and no macro variables that will do what you want for one numeric variable.

--
Paige Miller

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