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.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 4 replies
  • 1449 views
  • 2 likes
  • 3 in conversation