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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.