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 2025: Call for Content

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!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 439 views
  • 0 likes
  • 2 in conversation