Quartz | Level 8

Linear Equation with Date in x-axis

Hello,

I have this data:

data have;
infile datalines dlm='';
input bin_val \$8. variable_name \$6. _yyyymm_ yymmn6. PERCENT ;
format _yyyymm_ yymmn6.;
datalines;
6.0-7.0 alpha 201503 0.54
6.0-7.0 alpha 201506 0.48
6.0-7.0 alpha 201509 0.47
6.0-7.0 alpha 201512 0.85
6.0-7.0 alpha 201603 0.74
6.0-7.0 alpha 201606 0.9
6.0-7.0 alpha 201609 1.12
6.0-7.0 alpha 201612 1.01
6.0-7.0 alpha 201703 0.99
6.0-7.0 alpha 201706 0.43
6.0-7.0 alpha 201709 0.47
6.0-7.0 alpha 201712 .
6.0-7.0 alpha 201803 0.46
6.0-7.0 alpha 201806 0.37
6.0-7.0 alpha 201809 0.34
6.0-7.0 alpha 201812 0.38
6.0-7.0 alpha 201903 0.34
6.0-7.0 alpha 201906 0.32
6.0-7.0 alpha 201909 0.27
6.0-7.0 alpha 201912 0.26
6.0-7.0 alpha 202003 0.3
6.0-7.0 alpha 202006 0.25
6.0-7.0 alpha 202009 0.26
;run;

I want equation y=mx+b equation for percent on Y-axis and _YYYYMM_ on X-axis.

I was able to get below chart and equation in excel but not sure how to get this in SAS.

I want the equation more than the chart.

4 REPLIES 4
Tourmaline | Level 20

Re: Linear Equation with Date in x-axis

Copy the code back to SAS after pasting to ensure it can be run.

Quartz | Level 8

Re: Linear Equation with Date in x-axis

Updated. Apologies!!!
Tourmaline | Level 20

Re: Linear Equation with Date in x-axis

A simple Proc Reg call will give you both

ods select fitplot;
proc reg data = have;
model PERCENT = _yyyymm_;
run;quit;
Super User

Re: Linear Equation with Date in x-axis

"Dates" on month intervals are not evenly spaced and the regression is going to be just a bit suspect.

If you actually need to know the slope, m, per calendar month then you may be better off creating a sequence variable instead of using a date. Or use a proper timeseries procedure.

Discussion stats
• 4 replies
• 521 views
• 1 like
• 4 in conversation