BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
blakeellis18
Fluorite | Level 6

hi all,

 

I'm trying to create a histogram inside of a macro that uses a parameter variable of &Vbl. Does anyone know how to do this? my current code is:

%MACRO HistandStats ( DSNm = , Vbl = , Stats = N MEAN STDDEV ,
Ndec = 1);

TITLE1 "Histogram for &Vbl from Data Set &DSNm";
proc univariate data = work.DSNm;
histogram &Vbl;
run;

 

but this doesn't seem to work when I set DSNm and Vbl to specific values! thanks in advance.

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

If you intend to reference the data set with the DSNM macro variable then you need an & in front of DSNm. Since you currently are likely not referencing a data set then the variable &VBL is not found.

 

Instead of fixing the library name as you do with this code:

proc univariate data = work.DSNm;

it is usually  a better idea to use

proc univariate data = &DSNm.;

And then if desired you can pass the library name if needed in the macro call.

&HistandStats ( DSNm = mylib.somedateset, vbl= <other parameters you want);
 

View solution in original post

2 REPLIES 2
ballardw
Super User

If you intend to reference the data set with the DSNM macro variable then you need an & in front of DSNm. Since you currently are likely not referencing a data set then the variable &VBL is not found.

 

Instead of fixing the library name as you do with this code:

proc univariate data = work.DSNm;

it is usually  a better idea to use

proc univariate data = &DSNm.;

And then if desired you can pass the library name if needed in the macro call.

&HistandStats ( DSNm = mylib.somedateset, vbl= <other parameters you want);
 
blakeellis18
Fluorite | Level 6

yes thank you! I completely missed the "&" in front of DSNm. and I took your advice and changed it to &DSNm. instead of work.&DSNm and it worked. Thanks again!

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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
  • 2 replies
  • 1168 views
  • 1 like
  • 2 in conversation