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

Hi all,

 

Could you please help to code the 'Standard Error' for the gsplot. The plot has to be as below. What should be a standard of the dataset? What are the options for proc sgplot?

 

large (3).jpg

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

Try something like:

 

proc sql;
create table classGraph as
select 
    sex, 
    age, 
    mean(weight) as meanWeight, 
    mean(weight) - std(weight) as lowStdWeight,    
    mean(weight) + std(weight) as highStdWeight
from sashelp.class
group by sex, age;
quit;

proc sgplot data=classGraph;
scatter x=age y=meanWeight / 
    yerrorlower=lowStdWeight yerrorupper=highStdWeight group=sex;
series x=age y=meanWeight / lineattrs=(pattern=solid) group=sex;
run;
PG

View solution in original post

6 REPLIES 6
DanH_sas
SAS Super FREQ

The main options you want to use on the VLINE statement are the following:

 

1. LIMITSTAT = CLM | STDERR | STDDEV -- for your case, use STDERR

2. NUMSTD = <number> -- This is a multiplier for STDERR or STDDEV. The default is 1, which mean you would get one standard error in your case.

3. LIMITS = UPPER | LOWER | BOTH -- the default is BOTH, just like in your picture.

 

Here is a simple example:

proc sgplot data=sashelp.class;
vline age / response=weight stat=mean limitstat=stderr numstd=2;
run;

You can also modify the visual attributes of the error bars using the ERRORATTRS option.

 

Hope this helps!

Dan

DmytroYermak
Lapis Lazuli | Level 10

Thank you for the reply! Could you please say how to modify your code to draw two lines: one for 'male', another for 'female'.

And another question: if I have SE calculated in previous steps (this is an obligate rule) how to put SE on the plot in this case?

PGStats
Opal | Level 21

Try something like:

 

proc sql;
create table classGraph as
select 
    sex, 
    age, 
    mean(weight) as meanWeight, 
    mean(weight) - std(weight) as lowStdWeight,    
    mean(weight) + std(weight) as highStdWeight
from sashelp.class
group by sex, age;
quit;

proc sgplot data=classGraph;
scatter x=age y=meanWeight / 
    yerrorlower=lowStdWeight yerrorupper=highStdWeight group=sex;
series x=age y=meanWeight / lineattrs=(pattern=solid) group=sex;
run;
PG
PeterClemmensen
Tourmaline | Level 20

What does your data look like?

 

Perhaps something like this example?

 

http://support.sas.com/kb/42/542.html

DmytroYermak
Lapis Lazuli | Level 10

Thank you for the last link. I used it:

PGStats
Opal | Level 21

invalue defines an INFORMAT. You need a VALUE statement to define a format in proc format.

PG

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 6 replies
  • 5527 views
  • 7 likes
  • 4 in conversation