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

I am making a plot of mean and SD of an ordinal variable. Shell says to display n, mean, SD in appropriate manner. Anyone have suggestion on how to display n? I am plotting the ordinal variable over different study days. 

 

proc sgplot data=dsn;

vline folderseq / response=ordinal_visit stat=mean limitstat=stddev markers;

run;

lrackley_0-1610467688487.png

 

1 ACCEPTED SOLUTION

Accepted Solutions
DanH_sas
SAS Super FREQ

I can get you most of the way there:

proc sgplot data=dsn;
vline folderseq / response=ordinal_visit stat=mean limitstat=stddev markers;
xaxistable ordinal / stat=mean location=inside;
xaxistable ordinal / stat=freq location=inside;
run;

Unfortunately, you cannot currently compute the SD in the axis table.

 

Hope this helps!

Dan

View solution in original post

14 REPLIES 14
PaigeMiller
Diamond | Level 26

In PROC SGPLOT, you can use the VBOX statement with the DISPLAYSTATS= option. You could also use the NOTCHES option, where the smaller the "notch", the bigger the N.

 

In PROC BOXPLOT, you can use the BOXWIDTHSCALE= option to make the width of the boxplot proportional to N.

 

 

--
Paige Miller
tarheel13
Rhodochrosite | Level 12

Thanks for your response. Statistician wrote back to me and she is saying that n, mean, SD should be marked for each data point in the figure. Do you know how to do that? I am only aware of datalabel statement in SG plot. 

PaigeMiller
Diamond | Level 26

@tarheel13 wrote:

Thanks for your response. Statistician wrote back to me and she is saying that n, mean, SD should be marked for each data point in the figure. 


Does that mean for each DATE (not data point) on the x-axis?

--
Paige Miller
tarheel13
Rhodochrosite | Level 12

No, I don't think she means date. I have to get the mean, SD, and N for each study day and then the disease severity (moderate, severe, or all subjects). I imagine she would mean display mean, SD, and N for each point. If I specify datalabel, that will put the label for each marker on the figure. However, it sounds like she wants the SD and N too and that's what I was asking. 

 

See direct quote: "For the first line, I am saying that the N, Mean, standard deviation for each point should be marked in some manner in the figure for each data point of the figure."

PaigeMiller
Diamond | Level 26

"For the first line, I am saying that the N, Mean, standard deviation for each point should be marked in some manner in the figure for each data point of the figure."

 

Maybe we're just getting confused because you have one interpretation of those words and I have a different interpretation, but in my interpretation, a data point does not have an N, it does not have a mean and it does not have a standard deviation. (Or trivially, N=1 for each data point). In my interpretation, the x-axis positions on your plot (which are days) do have an N, a mean and a standard deviation, and I already explained how to create a boxplot that includes those values either graphically or textually.

--
Paige Miller
Reeza
Super User
Reporting a Standard Deviation and Mean for an Ordinal variable seems weird to be honest. Usually just counts and percentages are reported, though most frequent/median would also be of interest. I find it hard to understand how SD would be useful here.
tarheel13
Rhodochrosite | Level 12

Because it is a 1-8 scale of disease severity. I did not write the SAP so just trying to program according to SAP and shell. It is a measure of disease severity. So 8 means the patient is about to die and 1 is stable. Recovery is defined as this score reaching 1,2, or 3. 

PaigeMiller
Diamond | Level 26

@tarheel13 wrote:

Do you mean this?

https://blogs.sas.com/content/graphicallyspeaking/2015/12/23/box-plot-with-stat-table-and-markers/

 

Like the table underneath? 


I gave links to what I meant. But that link works too.

--
Paige Miller
DanH_sas
SAS Super FREQ

I can get you most of the way there:

proc sgplot data=dsn;
vline folderseq / response=ordinal_visit stat=mean limitstat=stddev markers;
xaxistable ordinal / stat=mean location=inside;
xaxistable ordinal / stat=freq location=inside;
run;

Unfortunately, you cannot currently compute the SD in the axis table.

 

Hope this helps!

Dan

tarheel13
Rhodochrosite | Level 12

Thank you. I will try this. The only other idea I have is to output a dataset from proc means and then do something like this:

proc means data=visits n mean stddev maxdec=2;

class sev folderseq;

var ordinal_visit;

output out=MeanOut n=n mean=mean stddev=SD;

run;

 

proc sgplot data=summary;

series x=folderseq y=mean/group=sev;

scatter x=folderseq y=mean / group=sev yerrrorlower=lowerSD yerrorupper=upperSD;

xaxistable SD;

run;

 

However, I don't really like how this looks lol. And for some reason, my formats of folderseq are not showing up. I had them set up to display Day 1, Day 3, etc. 

lrackley_0-1610476317470.png

 

DanH_sas
SAS Super FREQ

This should work for you:

proc means data=sashelp.class nway;
class age sex;
var weight;
output out=tempdata mean=Mean n=N stddev=StdDev;
run;

data tempdata2;
set tempdata;
lowerSD = Mean - StdDev;
upperSD = Mean + StdDev;
run;

proc sgplot data=tempdata2;
series x=age y=mean / group=sex;
scatter x=age y=mean / group=sex yerrorlower=lowerSD yerrorupper=upperSD;
xaxistable  N Mean StdDev / location=inside;
run;
tarheel13
Rhodochrosite | Level 12

She just told me that she needs to be able to estimate N, mean, SD for each data point. I do not know "appropriate manner" to display that. I was going to just print number of subjects underneath the figure and use datalabel statement to get mean for each point. I think the limitstat=stddev already shows the SD fine but it's not my call. 

 

@Reeza we do have stacked bar chart of ordinal scores in another version of shells. This figure is supposed to be for DSMB though. 

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 14 replies
  • 2756 views
  • 4 likes
  • 4 in conversation