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
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.
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.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.