DATA Step, Macro, Functions and more

Number of observations

Accepted Solution Solved
Reply
Contributor
Posts: 50
Accepted Solution

Number of observations

Hi everyone,

I have a dataset in which all the variables have a total observation of 68811 with there are no missing values. However, SAS uses only 68717 in regressions. Is there a way of ensuring that the number of observations equal the number of observations used in the regressions? 

 

Thank you.


Accepted Solutions
Solution
‎09-30-2017 09:18 PM
Trusted Advisor
Posts: 1,312

Re: Number of observations

You have 94 observations with at least one of

    nD_assets1 post nsize nlev ner ncash nGrowth nR_E nroa fic fyear sic2

missing.

 

If they are all numeric vars, you can find those cases by

 

data suspect;

  set have;

  where nmiss(nD_assets1, post nsize, nlev, ner, ncash, nGrowth, nR_E, nroa, fic, fyear, sic2)>0;

run;

View solution in original post


All Replies
Trusted Advisor
Posts: 1,312

Re: Number of observations

Show us the sas log, which will help us help you.

SAS Super FREQ
Posts: 497

Re: Number of observations

[ Edited ]

There are always one or more reasons why observations are excluded: missing values, nonpositive weights, or nonpositive frequencies.  Did you look at the number of observations table?  Does it agree with your assessment that there are no missing values?  You can output it to a data set and print it to see additional information about why observations were excluded.

 

data class;
   set sashelp.class;
   if uniform(7) lt 0.1 then height = .;
   if uniform(7) lt 0.1 then weight = .;
   f = uniform(7) > 0.1;
   w = uniform(7) > 0.1;
   run;
proc print; run;
proc reg;
   model weight = height;
   freq f;
   weight w;
   ods output nobs=n;
quit;
proc print; run;

 

Super User
Posts: 23,296

Re: Number of observations


Theo_Gh wrote:

Hi everyone,

I have a dataset in which all the variables have a total observation of 68811 with there are no missing values. However, SAS uses only 68717 in regressions. Is there a way of ensuring that the number of observations equal the number of observations used in the regressions? 

 

Thank you.


You need to post more information. 

SAS uses all non-misisng by default so either you have missing or a WHERE statement or something else that's not being stated. Most likely it's the third OR option here. 

 

Contributor
Posts: 50

Re: Number of observations

Sorry everyone; actually SAS does indicate that there are values. Problem is I can't identify them. 

 

The log is provided below:

 

proc surveyreg data=theo.final;
3 cluster gvkey;
4 class fic fyear sic2;
5 model nD_assets1= post nsize nlev ner ncash nGrowth nR_E nroa fic fyear sic2/solution ADJRSQ;
6 run;

NOTE: Writing HTML Body file: sashtml.htm
NOTE: In data set FINAL, total 68811 observations read, 94 observations with missing values are
omitted.
NOTE: PROCEDURE SURVEYREG used (Total process time):
real time 8.16 seconds
cpu time 2.96 seconds

 

Solution
‎09-30-2017 09:18 PM
Trusted Advisor
Posts: 1,312

Re: Number of observations

You have 94 observations with at least one of

    nD_assets1 post nsize nlev ner ncash nGrowth nR_E nroa fic fyear sic2

missing.

 

If they are all numeric vars, you can find those cases by

 

data suspect;

  set have;

  where nmiss(nD_assets1, post nsize, nlev, ner, ncash, nGrowth, nR_E, nroa, fic, fyear, sic2)>0;

run;

Contributor
Posts: 50

Re: Number of observations

data theo.new;
set theo.final;
where nmiss(nD_assets1, post nsize, nlev, ner, ncash, nGrowth, nR_E, nroa)>0;
run;

I used the code above but I'm getting a syntax error
SAS Super FREQ
Posts: 497

Re: Number of observations

put a comma between all of your variables (or use OF as I did then you don't need any commas).

SAS Super FREQ
Posts: 497

Re: Number of observations

data ...;

set ...;

if nmiss(of ... all analysis variables variable list...);

run;

proc print; run;

Contributor
Posts: 50

Re: Number of observations

Posted in reply to WarrenKuhfeld
Please bear with me.
The codes works now.I get a new dataset but when I use the new dataset in a regression, I get an error that there are no observations in the dataset even though there are
SAS Super FREQ
Posts: 497

Re: Number of observations

You asked how to find out how to identify the observations with missing values.  That is what I showed you.  You can't analyze that data set.  Analyze the original data set.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 10 replies
  • 261 views
  • 3 likes
  • 4 in conversation