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
Super User

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
Super User

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 2024

innovate-wordmarks-white-horiz.png

SAS is headed back to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team.

Interested in speaking? Content from our attendees is one of the reasons that makes SAS Innovate such a special event!

Submit your idea!

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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