BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
csetzkorn
Lapis Lazuli | Level 10

The following work fine for one measure

PROC SGPLOT DATA=SomeData;
	VBOX SomeMeasure
	/ category = SomeCategory NOOUTLIERS;
	title 'Todo';
RUN; 

Can this easily be extended to work with several measures? I can of course copy/adapt/past or even better use a macro but before I do this just wanted to check with the experts. thanks! 

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Reshape the data so that you have a categorical variable holding the name/description of the variable and the value.

One way is to transpose data twice or a data step.

Here's an example with double transposition:

Proc transpose data=sashelp.class out=work.classtrans;
   var height weight age;
run;
proc sort data=work.classtrans;
   by  _name_;
run;
proc transpose data=work.classtrans out=work.classtrans2;
 by  _name_;
 var col:;
run;

proc sgplot data=work.classtrans2;
   hbox col1 / category=_name_;
   label col1 ='Value distribution';
run;

If you have many observations and variables of concern this may be pretty resource intensive and the data step using an array holding the variables of interest and transposing that way while adding a categorical variable to hold the name or description may be better.

 

View solution in original post

3 REPLIES 3
PeterClemmensen
Tourmaline | Level 20

If I understand your request correctly, you want to create several VBOX plots based on distinct values of some variable?

 

If yes, do not resort to writing a macro loop. Instead, use by group processing like this

 

proc sort data=sashelp.heart out=heart;
	by sex;
run;

proc sgplot data=heart;
	by sex;
	vbox cholesterol / category=deathcause;
run;
PeterClemmensen
Tourmaline | Level 20

On further inspection of your request, I don't think that is what you mean.

 

Still, I would not use a macro loop. Do something like this

 

data have;
	input SomeData:$50. SomeMeasure:$50. SomeCategory:$50.;
	datalines;
sashelp.class Height Sex
sashelp.iris SepalWidth Species
sashelp.cars MPG_City Type
;

data _null_;
	set have;
	length arg $500;
	arg=cat("proc sgplot data=", SomeData, "; vbox ", SomeMeasure, "/ category = ", SomeCategory, "nooutliers; run;");
	call execute(arg);
run;
ballardw
Super User

Reshape the data so that you have a categorical variable holding the name/description of the variable and the value.

One way is to transpose data twice or a data step.

Here's an example with double transposition:

Proc transpose data=sashelp.class out=work.classtrans;
   var height weight age;
run;
proc sort data=work.classtrans;
   by  _name_;
run;
proc transpose data=work.classtrans out=work.classtrans2;
 by  _name_;
 var col:;
run;

proc sgplot data=work.classtrans2;
   hbox col1 / category=_name_;
   label col1 ='Value distribution';
run;

If you have many observations and variables of concern this may be pretty resource intensive and the data step using an array holding the variables of interest and transposing that way while adding a categorical variable to hold the name or description may be better.

 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 876 views
  • 4 likes
  • 3 in conversation