BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
MarioAQ
Calcite | Level 5

I have two variables trigliceridbefore and trigliceridafter I want to create a boxplot I cannot find the way. I did separately, but no in the same graphic.  

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

You don't show your data, but the data has to be arranged properly if you want both boxplots together in one plot.

 

Something like this:

 

data for_plot;
     input before_after $ triglyceride;
     cards;
before 24
after 31
before 39
after 33
...
before 66
after 70
;

So if your data is not in this form, you will have to manipulate it.

--
Paige Miller

View solution in original post

3 REPLIES 3
Reeza
Super User
Depends on your data structure partly. Can you show an example of your data and what you've tried so far?

There are many tutorials out there and here's a link to one. The code is at the bottom of the page to download or you should be able to run it directly if you copy/paste it.
https://blogs.sas.com/content/graphicallyspeaking/2016/12/08/getting-started-sgplot-part-3-vbox/
PaigeMiller
Diamond | Level 26

You don't show your data, but the data has to be arranged properly if you want both boxplots together in one plot.

 

Something like this:

 

data for_plot;
     input before_after $ triglyceride;
     cards;
before 24
after 31
before 39
after 33
...
before 66
after 70
;

So if your data is not in this form, you will have to manipulate it.

--
Paige Miller
PGStats
Opal | Level 21

Here is an example to get you started:

 

data test;
input id  trigliceridbefore   trigliceridafter;
datalines;
1   10.04   11.62
2   10.24   11.98
3   10.76   11.48
4   10.41   11.31
5   10.56   11.56
6   10.62   11.31
7   10.52   11.40
8   10.69   11.13
9   10.31   11.74
10  10.10   11.45
;

proc transpose data=test out=graphData;
by id;
var triglicerid: ;
label trigliceridbefore="Before"   trigliceridafter="After";
run;

proc sgplot data=graphData noautolegend;
vbox col1 / category=_label_;
xaxis display=(nolabel) reverse;
yaxis label="Triglicerides (<Units>)";
run;

TriglicerideBoxPlot.png

PG

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

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

View all other training opportunities.

Discussion stats
  • 3 replies
  • 474 views
  • 0 likes
  • 4 in conversation