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

I apply the proc sgplot to put two PDF curves on one graph, like the code below:

 

proc sgplot data=have;
density var1 / legendlabel="var1" lineattrs=(pattern=solid);
density var2 / legendlabel="var2" lineattrs=(pattern=dot);
xaxis label="value";
run;

 

then, I try to add the mean and std for both curves, which can be done in proc univariate by the inset statement: 

inset normal(mu sigma);

 

I think that the inset statement does not work in the same way in proc sgplot as it does in proc univariate. Any idea to let the above proc sgplot also output mean and std for both PDF curves? Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

Here is an example of one of many ways to display these statistics:

 

proc univariate data=sashelp.heart noprint;
var ageatstart ageatdeath;
output out=ageStats mean=muStart muDeath std=stdStart stdDeath;
run;

data _null_;
set ageStats;
str = catt(put(muStart,4.1),"/(",put(stdStart,4.2),")");
call symputx("startLabel",str);
str = catt(put(muDeath,4.1),"/(",put(stdDeath,4.2),")");
call symputx("deathLabel",str);
run;

proc sgplot data=sashelp.heart;
density ageatstart / legendlabel="Start Age" 
    curvelabel="&startLabel" curvelabelpos=max splitchar="/" splitjustify=center
    lineattrs=(pattern=solid);
density ageatdeath / legendlabel="Death Age" 
    curvelabel="&deathLabel" curvelabelpos=max splitchar="/" splitjustify=center
    lineattrs=(pattern=dot);
xaxis label="Age";
run;

SGPlot2.png

PG

View solution in original post

4 REPLIES 4
Rick_SAS
SAS Super FREQ

Yes, you are exactly right. PROC SGPLOT is primarily a graphical procedure. It does not contain the same analytical capabilities as ROC UNIVARIATE.  In particular, the INSET statement requires that you specify the text to display, which means you probably want to use PROC UNIVARIATE to fit the distribution to the data. Let's say that PROC UNIVARIATE displays a table that states that the parameters are mu=1.2 and sigma=3.4. Then you might use the following INSET statement in PROC SGPLOT:

inset ("mu" = "1.2" "sigma" = "3.4") / border;

 

PGStats
Opal | Level 21

Here is an example of one of many ways to display these statistics:

 

proc univariate data=sashelp.heart noprint;
var ageatstart ageatdeath;
output out=ageStats mean=muStart muDeath std=stdStart stdDeath;
run;

data _null_;
set ageStats;
str = catt(put(muStart,4.1),"/(",put(stdStart,4.2),")");
call symputx("startLabel",str);
str = catt(put(muDeath,4.1),"/(",put(stdDeath,4.2),")");
call symputx("deathLabel",str);
run;

proc sgplot data=sashelp.heart;
density ageatstart / legendlabel="Start Age" 
    curvelabel="&startLabel" curvelabelpos=max splitchar="/" splitjustify=center
    lineattrs=(pattern=solid);
density ageatdeath / legendlabel="Death Age" 
    curvelabel="&deathLabel" curvelabelpos=max splitchar="/" splitjustify=center
    lineattrs=(pattern=dot);
xaxis label="Age";
run;

SGPlot2.png

PG
Jonate_H
Quartz | Level 8

Thank you all for your kindly help 

Jonate_H
Quartz | Level 8

I add  name="curve1" and name="curve2" in those two  density statements, separately. So that legendlabel can also display.

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

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

View all other training opportunities.

Discussion stats
  • 4 replies
  • 1291 views
  • 2 likes
  • 3 in conversation