Dear all,
assuming I have this code and I wish to add a linear such as a regression line to show the trend of the curve
how do I do that
data have;
infile datalines;
input year 4. pats_stage1_3 pats_total 3. ;
datalines;
1999 150 300
2000 112 369
2001 236 426
2002 121 400
2003 330 520
2004 280 500
;
run;
proc sgplot data=have noborder;
series x=year y=pats_stage1_3 / lineattrs=(color=blue);
series x=year y=pats_total / lineattrs=(color=green) ;
xaxis type=discrete display=(nolabel) discreteorder=data offsetmin=0.1 offsetmax=0.1 ;
yaxis display =(nolabel) values=(0 to 600 by 100) valueattrs=(family=arial size=5pt ) minor grid ;
keylegend / location=outside position=bottom title="" valueattrs=(size=7pt family=arial) outerpad=(top=0.2cm) noborder;
run;
Hello @Anita_n,
You can add REG statements like these
reg x=year y=pats_stage1_3 / nomarkers lineattrs=(color=blue pattern=dash) legendlabel='Regr. stage 1-3';
reg x=year y=pats_total / nomarkers lineattrs=(color=green pattern=dash) legendlabel='Regr. total';
to your PROC SGPLOT step and remove the type=discrete option from the XAXIS statement to make them work.
Hello @Anita_n,
You can add REG statements like these
reg x=year y=pats_stage1_3 / nomarkers lineattrs=(color=blue pattern=dash) legendlabel='Regr. stage 1-3';
reg x=year y=pats_total / nomarkers lineattrs=(color=green pattern=dash) legendlabel='Regr. total';
to your PROC SGPLOT step and remove the type=discrete option from the XAXIS statement to make them work.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.
Ready to level-up your skills? Choose your own adventure.