BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
ari2495
Obsidian | Level 7

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:

ari2495_0-1667569751256.png

what is the error of the second variable about?

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

@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;

View solution in original post

8 REPLIES 8
Tom
Super User Tom
Super User

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?

ari2495
Obsidian | Level 7

Thank you for the help. Actually, I have already run this code for singular variables and it works

Tom
Super User Tom
Super User

@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;
Tom
Super User Tom
Super User

@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;
ari2495
Obsidian | Level 7
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.

Tom
Super User Tom
Super User

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
Obsidian | Level 7
yes and it worked but I need an automatized code
PaigeMiller
Diamond | Level 26

@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-...

--
Paige Miller

sas-innovate-wordmark-2025-midnight.png

Register Today!

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.


Register now!

Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 8 replies
  • 977 views
  • 0 likes
  • 3 in conversation