Hi, I really need some help on the BY statement in proc reg.
I want to regress the impl_volatility on delta variable but I want to do so for every security same ID) on every day t (same date) for securities with the same expiry date (exdate) on that day. In a day, there are different options with different expiry dates. Therefore, I expect to have more than one slope coefficient on same date t.
First I sort the data with
proc sort data=A1;
by cusip exdate date;
run;
Second, I run the regression with:
proc reg data=A1 outest=A2;
model impl_volatility=delta;
by cusip exdate date;
run;
However, this doesn't work. Can someone please help me out? Thank you.
You didn't say what is wrong.
Do you really want to group by cusip/exdate/date? Are there lots of observations with the same cusip/exdate/date for the regression to process?
PLEASE describe how it "doesn't work". Do you get an error? No result? Unexpected result - describe what you think the expected result should be.
Provide data if you want code tested. https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... shows how to turn a SAS dataset into data step code you can post so that we can duplicate your data.
I suspect that you actually get into a very long process because of all the graphs that proc reg is making by default (for each BY group).
Try
proc reg data=A1 outest=A2 plots=none;
Thank you all for your contribution. It is much appreciated. It turns out the code was okay and the problem was the small number of data for regression after grouping with by.
"On average there are 3 observations in the same group. But that is exactly what I need it to be to get my result."
And you want 1 regression per by group? Models won't even be estimated if the by group size does not have 2 more obs than there are independent variiables. What possible use would it be?
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.