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!
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: