capture statistic from proc reg to create a macro variable

Accepted Solution Solved
Reply
Contributor
Posts: 66
Accepted Solution

capture statistic from proc reg to create a macro variable

I have a simple linear regression model given below.

data aa;

input Y X @@;

datalines;

20 8 21 10 19 12 27 15 17 9 29 14 24 12

;

Proc reg data=aa;

model Y=X;

run;

The output is

My question,

How can I create a macro variable or simply extract regression coefficient b1= 1.40288 from above output so that it can be used in another program?

Thanks in advance!

Raghu.


Accepted Solutions
Solution
‎11-29-2012 12:10 PM
Super User
Posts: 19,822

Re: capture statistic from proc reg to create a macro variable

data aa;

input Y X @@;

datalines;

20 8 21 10 19 12 27 15 17 9 29 14 24 12

;

Proc reg data=aa;

model Y=X;

ods output ParameterEstimates=estimates;

run;

data _null_;

    set estimates;

    if variable="X" then call symput("slope", estimate);

run;

%put &slope.;

View solution in original post


All Replies
Solution
‎11-29-2012 12:10 PM
Super User
Posts: 19,822

Re: capture statistic from proc reg to create a macro variable

data aa;

input Y X @@;

datalines;

20 8 21 10 19 12 27 15 17 9 29 14 24 12

;

Proc reg data=aa;

model Y=X;

ods output ParameterEstimates=estimates;

run;

data _null_;

    set estimates;

    if variable="X" then call symput("slope", estimate);

run;

%put &slope.;

Super Contributor
Posts: 273

Re: capture statistic from proc reg to create a macro variable

Well you need to

-first discover the names of the ods parts with the use  ods trace on;   ods trace off; statements

-in a second time, you need to capture the right content into a table (here a in the work)

*ods trace on;

ods select ParameterEstimates;

ods output  ParameterEstimates=a;

Proc reg data=aa;

model Y=X;

run;

quit;

ods select all;

ods output close;

*ods trace off;

-and at final, you need to create the macro variable reading the sas dataset coming from ods

data _null_;

set a;

call symputx("secestim",estimate);

run;

%put &secestim;

HTH

Andre

Contributor
Posts: 66

Re: capture statistic from proc reg to create a macro variable

Thanks for the help!

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 688 views
  • 0 likes
  • 3 in conversation