BookmarkSubscribeRSS Feed
hodgeswc
Calcite | Level 5

Hello, 

 

I am currently attempting to run regression models on 5 stocks: JPM, PFE, FB, AMZN, and PEP. (2011-2015)

 

I have combined this data with fama french factors over the past 5 years as well. I have written code to sort the data and run descriptive statistics, however, I am not able to run the regressions because of the error: ERROR: No valid observations are found.

I only see this error at the bottom of my code when I attempt to run two regression models. It staes, for example, 

"ERROR: No valid observations are found.
NOTE: The above message was for the following BY group:
Ticker Symbol=JPM"
 
I'm not sure why I keep getting this error or how to fix it, it's the only thing preventing me from running a clean output. 
 
Here is my full code: 
 
data one;
Set x1.portfolio;
run;

data two;
set x1.famafrench;
run;

data one;
set one;
month = month(date);
year = year(date);
run;

proc sort data = one;
by month year;
run;

data two;
set two;
month = month(ffdate);
year = year(ffdate);
run;

proc sort data = two;
by month year;
run;


data all;
merge one two;
by month year;
ex_ret = ret - RF;
run;

proc sort data = all;
by ticker;
run;

proc means data = all;
var ret vwretd rf;
run;

proc means data = all;
by ticker;
var ret vwretd rf;
Title 'Descriptive Statistics by Ticker';
run;

proc reg data = all;
by ticker;
model ex_ret = mktrf;
Title 'CAPM Regression Models';
run;

proc reg data = all;
by ticker;
model ex_ret = smb hml mktrf umd;
title '4 Factor Regression';
run;

If anyone coud help it would be EXTREMELY appreciated. 
5 REPLIES 5
Reeza
Super User

This isn't an issue with code but an issue with data. 

Check your data for those ticker symbols and make sure it's valid.

hodgeswc
Calcite | Level 5

I found two issues within the data, but the rest is fine. Is there a way to delete two specific rows of data out of 285? I have everything downloaded from WRDS so I cant necessarily exclude this issue as it will happen every time I try to redownload. 

 

Thanks 

Reeza
Super User

Depends on the issue. If you can identify it and flag it with a variable you can add a WHERE clause to the remaining steps or filter it out. Depending on the issue SAS will filter records out, which is why you get a NO RECORDS error because there are no valid records for whatever you're trying to do. 

ballardw
Super User

A suggestion to help maintain code and increase program effeciency:

Instead of

 

data one;
Set x1.portfolio;
run;

data one;
set one;
month = month(date);
year = year(date);
run;

 

Do that in one step (and the same for data two).

data one;
   Set x1.portfolio;
   month = month(date);
   year = year(date);
run;

You take twice as much computer time with the separate data step to add the two variables. This may not seem like much for a small data set but considering we have users on this forum with datasets with trillions of records the time could be significant.

 

Also the construct of input and output data set the same are rife with opportunities to cause data problems that are hard to diagnose. And every additional step with the same data set increases the complexity of finding where something went wrong.

Tom
Super User Tom
Super User

Most likely the issue is with the regression steps. Perhaps there are not enough valid observations for some TICKER values to SAS to perform a regression. 

You could probably output something from PROC MEANS or PROC SQL to test which TICKER values you need to exclude.

 

proc sql noprint;
  select quote(trim(ticker)) into :bad_list separated by ' '
  from all
  group by ticker 
  having count(*)=1
  ;
quit;
proc reg data=all;
  where ticker not in (&bad_list);
  ...

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 5 replies
  • 15212 views
  • 0 likes
  • 4 in conversation