Hi all,
For class I am tasked with creating a macro program that will pull from all data sets and all numeric variables to create a histogram and summary statistics table.
Here is what I was given:
Write a macro program named ‘**********’ which may be used to summarize a numeric variable from any data set.
The macro will generate 2 pieces of output: 1) a histogram, and 2) summary statistics (i.e. the macro should contain 2 steps).
This is where I'm at right now and things are not matching up very well after trying to model after an existing program:
%MACRO ********** (****** = , Stats = N MEAN STDDEV, **** = _NUMERIC_, NDec= 1 );
DATA WORK.&****;
SET &***;
WHERE *** = "&***";
RUN;
TITLE1 "***********************";
PROC MEANS
DATA = WORK.&**** &Stats;
VAR &***;
RUN;
PROC SORT DATA = WORK.&****;
BY DESCENDING &****;
RUN;
TITLE1 "*******************************";
PROC PRINT DATA = WORK.&**** ;
VAR &***;
RUN;
TITLE;
%MEND ********;
%************ (******* = &*****, **** = &****, Stats = &Stats)
I am particularly concerned about what I should place in lieu of variable names throughout the program.
Step 1 in any macro writing effort is to create code without macros and without macro variables, and get it to work in one instance (such as, for one specific table and one specific variable). It does not seem as if you have done this. Once you have such a working SAS program, then it should be relatively easy to turn it into a macro. If you don't have working SAS code and try to turn it into a macro, then it will never work inside the macro.
So, show us code that works for one instance without macros and without macro variables.
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!
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.