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!
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;
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;
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;
Thank you all for your kindly help
I add name="curve1" and name="curve2" in those two density statements, separately. So that legendlabel can also display.
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.
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.