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.

SAS Innovate 2025: Call for Content

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 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 1 reply
  • 2927 views
  • 0 likes
  • 2 in conversation