Help using Base SAS procedures

DIFFICULT REGRESSION

Accepted Solution Solved
Reply
Contributor
Posts: 35
Accepted Solution

DIFFICULT REGRESSION

Hi Guys,

I need help with performing a regression with SAS.

Currently I have monthly data that goes on for 40 years. In each month, there is are companies along with variables (a and b ), and I want to regress variables a and b against each other to get the slope for that company.

For e.g:

Date                Company      A            B

19650701               001        xx1        yy1

19650702               001        xx2        yy2

19650703               001        xx3        yy3

(Company 001 will be featured for the whole of July 1965)

19650701               002       aa1         bb1

19650702               002       aa2         bb2

(Company 002 will be featured for the whole of July 1965)

Then going to the next month

19650801              001       .....          .....

19650802              001      .....           .....

(Company 001 will again be featured for the whole of Aug 1965)

19650801             003        ......        ........

19650802             003        ......       ........

(In Aug, there is a new company 003, and it will also be seen for the whole Aug)

So basically I am trying to regress variables A and B for each company for each month. Then moving on to the next month, it will again regress variables A and B for each company for that month. (ie. regress Company 001's variable A and B for July, Company 002's variable A and B for July;  regress Company 001's variable A and B for Aug, Company 003's variable A and B for Aug).

Note that the data set goes on for 40 years.

So there are 2 main difficult here:

1) How do I perform a regression?

2) How can I code it such that the it regresses Variable A and B for THAT company in THAT month, before moving on to the next month

Hope I'm clear with my problem.

Thanks guys!


Accepted Solutions
Solution
‎10-10-2012 01:41 AM
Super User
Posts: 9,662

Re: DIFFICULT REGRESSION

The most handy approach is using BY statement .

data have;

set have;

year=year(date);

month=month(date);

run;

proc sort data=have ;by company year month;run;

proc reg data=have;

by company year month;

model a=b ;

............

View solution in original post


All Replies
Solution
‎10-10-2012 01:41 AM
Super User
Posts: 9,662

Re: DIFFICULT REGRESSION

The most handy approach is using BY statement .

data have;

set have;

year=year(date);

month=month(date);

run;

proc sort data=have ;by company year month;run;

proc reg data=have;

by company year month;

model a=b ;

............

Respected Advisor
Posts: 3,777

Re: DIFFICULT REGRESSION

You can use a FORMAT to group the dates (SAS Dates) with no need to create new variables.  The values of DATE will need to be sorted properly of course.

data reg;
   do company=1 to 2;
     
do date = today()-90 to today();
         a = rannor(0);
         b = rannor(0);
         output;
        
end;
     
end;
  
run;
proc reg;
  
by company date;
   format date yymon.;
  
model a = b;
  
run;
Super User
Posts: 9,662

Re: DIFFICULT REGRESSION

Yes. I know it. Just explain it detail to OP. OP maybe feel strange for by option groupformat .

proc reg;
  
by company date groupformat  ;
   format date yymon.;
  
model a = b;
  
run;

☑ This topic is SOLVED.

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

Discussion stats
  • 3 replies
  • 202 views
  • 6 likes
  • 3 in conversation