BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Benn
Calcite | Level 5

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!

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

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

3 REPLIES 3
Ksharp
Super User

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 ;

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

data_null__
Jade | Level 19

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;
Ksharp
Super User

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;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 3 replies
  • 894 views
  • 6 likes
  • 3 in conversation