SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
crawfjor
Calcite | Level 5

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

  • The macro should contain the following 4 parameters:
  • '*****’ to specify the data set name
  • '***’ to specify the numeric variable
  • ‘****’ to specify summary statistics.  Include default statistics of N, MEAN, and STDDEV.
  • ‘****’ to specify the number of decimals.  Include a default value of 1.

 

 

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.

1 REPLY 1
PaigeMiller
Diamond | Level 26

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.

--
Paige Miller

sas-innovate-white.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.

 

Early bird rate extended! Save $200 when you sign up by March 31.

Register now!

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
  • 1 reply
  • 598 views
  • 0 likes
  • 2 in conversation