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