BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Anita_n
Pyrite | Level 9

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;

 

1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

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.

View solution in original post

1 REPLY 1
FreelanceReinh
Jade | Level 19

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.

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 4419 views
  • 0 likes
  • 2 in conversation