- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hey,
I'm new to SAS and I try to create side-by-side box plots in SAS university, one for each variable - since days now.
My dataset "income" looks like this:
The assignment is: create side by side box plots for the income for income1, income2, and income3 and comment on this plot.
I guess output shall look like this:
but instead of alpha beta gamma: income1 income2 income3.
proc sgplot data=income;
vbox income1/category=income2;
run;
gives me not even the desired outcome for one boxplot...
After hours and hours of trying I still have no idea how to solve this.
I really hope, you can help me.
Thank you!
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
HEUREKA!!!
solution:
FILENAME REFFILE '/folders/myfolders/LAB/Income.csv'; PROC IMPORT DATAFILE=REFFILE DBMS=CSV OUT=WORK.IMPORT1; GETNAMES=YES; RUN; PROC CONTENTS DATA=WORK.IMPORT1; RUN; proc sort data=import1; by name; run; proc transpose data=import1 out=boxplot; var income1 income2 income3; by name; run; proc sgplot data=boxplot; vbox col1/category=_name_; run;
It is necessary to proc sort before proc transpose can be run.
out=boxplot (rename=(col1=income class)); was not accepted and caused an error. I coudn't figure out, why...
Thank you so so so much, all! I am soooo happy right now!
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Lacona,
To get the boxplot you are looking for, you need to transpose the data first to get 3 columns:
Name, IncomeClass (with values Income1, Income2, and Income3), and the value of the income.
The elegant way to do it is to use PROC TRANSPOSE. However, with this little data, you can just retype the data.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Just to be sure: after proc transpose my dataset should look like this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Your variable INCOME2 is not a category variable, it is a continuous variable, and so it will not work in PROC SGPLOT as an x-axis category variable.
Instead, you need to re-arrange your data so that you have a category variable to put on the x-axis.
This PROC TRANSPOSE example does exactly what you want, it creates a category variable that you can use on your x-axis.
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
proc transfer doesn't work:
I get this pop-up saying "the chart "WORK.DATA4" can't be opened, because it doesn't contain columns."
Simple transpose worked:
Boxplot doesn't work as wished either:
I'm so sorry that I can't run it, but I just started working with SAS last week.
Thank you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You need to use the OUT= option on PROC TRANSPOSE, as shown in the example.
Then you should be able to run PROC SGPLOT on the data set created by PROC TRANSPOSE.
If that doesn't work, show us the entire SAS log (not just the errors) including PROC TRANSPOSE and PROC SGPLOT as text (not as a screen capture) by clicking on the {i} icon and pasting the log into the window that appears. This preserves the formatting of the log and makes it more readable. Do not provide the log via any other method.
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Next try - didn't work:
sigh.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
FILENAME REFFILE '/folders/myfolders/LAB/Income.csv'; PROC IMPORT DATAFILE=REFFILE DBMS=CSV OUT=WORK.Income; GETNAMES=YES; RUN; PROC CONTENTS DATA=WORK.income; RUN; proc print data=income;
run; run; proc transpose data=income out=boxplot (rename=(col1=income class)); var _income1 _income2 _income3; by name; run;
Thank you for the hint with the I-icon! It is ways easier.
This code gives me ERROR 79-322: expecting a =.
It is not possible to generate a transposed data set.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
But this is not a LOG, this is your actual code. We need to see the LOG by pasting it into the {i} icon window. And you don't show the PROC SGPLOT, we need to see the LOG of that part as well.
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK; 72 73 proc transpose data=income out=boxplot (rename=(col1=income class)); _ 79 ERROR 79-322: Expecting a =. 74 var _income1-_income3; 75 by name; 76 run; NOTE: The SAS System stopped processing this step because of errors. WARNING: The data set WORK.BOXPLOT may be incomplete. When this step was stopped there were 0 observations and 0 variables. WARNING: Datei WORK.BOXPLOT wurde nicht ersetzt, da da dieser Schritt angehalten wurde. NOTE: Verwendet wurde: PROZEDUR TRANSPOSE - (Gesamtverarbeitungszeit): real time 0.00 seconds cpu time 0.01 seconds 77 78 79 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK; 91
Oh! Sure! This is the log I got.
There is no sgplot to show, because the transpose didn't run?!
Without proper transpose no proc sgplot?
Thank you so much for your help!!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi;
What is the purpose of CLASS in the RENAME= option? Why is the variable there. The RENAME= option expects pairs of variables...
(rename=(oldname=newname old2=new2 old3=new3)) ... your code does not follow that syntax rule.
Cynthia
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hey,
I wanted 'income class' as title for the new column and I copied exactly the template from the SAS Help Center:
I have no idea, why it didn't work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
label income_class='Income Class';
Cynthia
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thank you! It worked out perfectly fine with income_class.
Now I'm trying to have more values shown on the y-axis.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
HEUREKA!!!
solution:
FILENAME REFFILE '/folders/myfolders/LAB/Income.csv'; PROC IMPORT DATAFILE=REFFILE DBMS=CSV OUT=WORK.IMPORT1; GETNAMES=YES; RUN; PROC CONTENTS DATA=WORK.IMPORT1; RUN; proc sort data=import1; by name; run; proc transpose data=import1 out=boxplot; var income1 income2 income3; by name; run; proc sgplot data=boxplot; vbox col1/category=_name_; run;
It is necessary to proc sort before proc transpose can be run.
out=boxplot (rename=(col1=income class)); was not accepted and caused an error. I coudn't figure out, why...
Thank you so so so much, all! I am soooo happy right now!