Write and run SAS programs in your web browser

ERROR: No valid observations are found.

Reply
New Contributor
Posts: 3

ERROR: No valid observations are found.

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. 
Grand Advisor
Posts: 16,304

Re: ERROR: No valid observations are found.

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.

New Contributor
Posts: 3

Re: ERROR: No valid observations are found.

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 

Grand Advisor
Posts: 16,304

Re: ERROR: No valid observations are found.

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. 

Grand Advisor
Posts: 9,699

Re: ERROR: No valid observations are found.

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.

Super User
Super User
Posts: 5,964

Re: ERROR: No valid observations are found.

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);
  ...
Post a Question
Discussion Stats
  • 5 replies
  • 123 views
  • 0 likes
  • 4 in conversation