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