Data visualization with SAS programming

Standard Error (SE) in 'proc sgplot'

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 146
Accepted Solution

Standard Error (SE) in 'proc sgplot'

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?

7.jpg

 Thank you!

 

 


Accepted Solutions
Solution
‎11-03-2017 09:59 AM
Respected Advisor
Posts: 4,973

Re: Standard Error (SE) in 'proc sgplot'

Posted in reply to DmytroYermak

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


All Replies
SAS Super FREQ
Posts: 945

Re: Standard Error (SE) in 'proc sgplot'

Posted in reply to DmytroYermak

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

Frequent Contributor
Posts: 146

Re: Standard Error (SE) in 'proc sgplot'

[ Edited ]

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?

Solution
‎11-03-2017 09:59 AM
Respected Advisor
Posts: 4,973

Re: Standard Error (SE) in 'proc sgplot'

Posted in reply to DmytroYermak

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
PROC Star
Posts: 851

Re: Standard Error (SE) in 'proc sgplot'

Posted in reply to DmytroYermak

What does your data look like?

 

Perhaps something like this example?

 

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

Frequent Contributor
Posts: 146

Re: Standard Error (SE) in 'proc sgplot'

Thank you for the last link. I used it:

 

proc sgplot data=t4 noautolegend;                                                                                                  
   scatter x=PCTPT y=mean / group=TRT01A
                           yerrorlower=lower                                                                                            
                           yerrorupper=upper                                                                                            
                           markerattrs=(color=blue symbol=CircleFilled);                                                                
   series x=PCTPT y=mean / lineattrs=(color=blue pattern=2);
 run; 

and received draft plot.

 

On the same time the format statement (inside the procedure step):

 

format PCTPT $PCTPTF.;

is not functioning. I receive the following message in the log:

 

ERROR: The format $PCTPTF was not found or could not be loaded.

The format was defined at the very beginning of the code:

 

proc format;
  invalue $PCTPTF
    "Pre dose" 			  = "Timepoint"
	"15 mins Post dose"   = "0.25"
	"30 mins Post dose"   = "0.5"
	"1 hr Post dose"      = "1"
	"2 hrs Post dose"     = "2"
	"4 hrs Post dose"     = "4"
	"6 hrs Post dose"     = "6"
	"9 hrs Post dose"     = "9"
	"12 hrs Post dose"    = "12"
	"24 hrs Post dose"    = "24"
	"36 hrs Post dose"    = "36"
	"48 hrs Post dose"    = "48"
	"60 hrs Post dose"    = "60"
	"Visit 8" 			  = "96"
	"Visit 10" 			  = "168";
run;

Could you please advise how to manage the issue.

Respected Advisor
Posts: 4,973

Re: Standard Error (SE) in 'proc sgplot'

Posted in reply to DmytroYermak

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

PG
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 128 views
  • 7 likes
  • 4 in conversation