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!

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

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