Hi! I run my code correctly, the i created a macro with let statement, and the other commands work. The only one which does not work is boxplot. please, help is welcome.
here is the code
proc import
datafile="file"
dbms= xlsx
out=pdrating;
run;
/*macro*/
%let vars= mean_PD loss_days;
/*proc freq variabili */
proc freq data=pdrating;
tables &vars./missing;
run;
/*Boxplot verticale e orizzontale*/
proc sgplot data= pdrating;
vbox &vars.;
run;
here's log:
what is the error of the second variable about?
@ari2495 wrote:
Thank you for the help. Actually, I have already run this code for singular variables and it works
Like I said, try creating the PROC SGPLOT code manually first. Once you have code that works then you can see how to get the macro to generate it.
So if you have a macro variable named VARS you and want to do something with each name in the list you would use code like this:
%do index=1 %to %sysfunc(countw(&vars,%str( )));
%let varname=%scan(&vars,&index,%str( ));
.... code that uses &VARNAME ....
%end;
Unlike the TABLES statement in PROC FREQ, the VBOX statement in PROC SGPLOT only accepts ONE variable.
https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/grstatproc/n1waawwbez01ppn15dn9ehmxzihf.htm
You could try issue multiple VBOX statements?
Get the actual SAS code working without macro logic first. Then figure out how to get the macro to generate that code.
So what PROC SGPLOT code do you want to run when you have multiple analysis variables?
Thank you for the help. Actually, I have already run this code for singular variables and it works
@ari2495 wrote:
Thank you for the help. Actually, I have already run this code for singular variables and it works
Like I said, try creating the PROC SGPLOT code manually first. Once you have code that works then you can see how to get the macro to generate it.
So if you have a macro variable named VARS you and want to do something with each name in the list you would use code like this:
%do index=1 %to %sysfunc(countw(&vars,%str( )));
%let varname=%scan(&vars,&index,%str( ));
.... code that uses &VARNAME ....
%end;
@ari2495 wrote:
Thank you for the help. Actually, I have already run this code for singular variables and it works
And did you try it for multiple variables or not?
Does something like this do what you want?
proc sgplot data=sashelp.class;
vbox age;
vbox height;
run;
quit;
Or do you want something like this instead?
proc sgplot data=sashelp.class;
vbox age;
run;
vbox height;
run;
quit;
proc sgplot data=sashelp.class;
vbox age;
vbox height;
run;
quit;
this one does not work for me because I need a code that generates a single boxplot for every single variable.
proc sgplot data=sashelp.class;
vbox age;
run;
vbox height;
run;
quit;
with regard to this one, I run this too but it only gave me boxplot for age variable.
So did you try a separate PROC step for each one?
proc sgplot data=sashelp.class;
vbox age;
run;
proc sgplot data=sashelp.class;
vbox height;
run;
@ari2495 wrote:
yes and it worked but I need an automatized code
This was already posted by @Tom earlier in this thread at https://communities.sas.com/t5/New-SAS-User/how-to-create-boxplot-referencing-multiple-variables-of-...
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.