OBS AND OUTOBS

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 17
Accepted Solution

OBS AND OUTOBS

Hi,

 

I wanted to know the difference between obs and outobs.

 

Thanks.


Accepted Solutions
Solution
‎04-16-2018 01:26 AM
PROC Star
Posts: 266

Re: OBS AND OUTOBS

Posted in reply to katariasarthak

OBS can be a system option or a dataset option, it limits the number of observarions read in a proc or a datastep. OBS normally decides the number of the last observation read. If, however, you have tables with "holes" in them (deleted observations), the results can vary a bit.

Look at this:

data x;
  do i=1 to 10;
    output;
    end;
run;

proc sql; /* delete the first observation */
  delete from x where i=1;
quit;

options obs=5;
data y;
  set x;
run;

data z;
  set x(firstobs=3);
run;

The Y table contains 5 observations, which are i=2 to 6. Because the read started from the beginning, SAS new that an observation was deleted, and adjusted the number to read accordingly.

But the Z table contains 3 observations (as expected), with I values from 3 to 5 (not as expected), because SAS did not read from the start of the table (because of the FIRSTOBS option) ,and therefore did not realize that the first observation was deleted. 

 

The OUTOBS option is ony used in PROC SQL. It can used either in the SQL invocation ("proc SQL OUTOBS=<number>;") or in a RESET Statement. It does not limit the amount of processing done, except that processing stops once the desired number of observations has been output in the statement.

Compare this:

options obs=1;
proc sql;
  select sum(age) from sashelp.class;
quit;
options obs=max;
proc sql outobs=1;
  select sum(age) from sashelp.class;
quit;

The first PROC SQL call will return 14, which is the age of the first person in the dataset (only one record is read). The second SQL call will give you 253, which is the sum of all the ages in the class (OUTOBS does nothing here, as only one sum is to be returned anyway, all the records are read).

View solution in original post


All Replies
Respected Advisor
Posts: 3,040

Re: OBS AND OUTOBS

Posted in reply to katariasarthak

Please provide some context for this question.

--
Paige Miller
Super User
Super User
Posts: 9,599

Re: OBS AND OUTOBS

Posted in reply to katariasarthak

Thats very vague, I mean the difference could be that the first has three less characters?  Have you read the manual for these items in relevance to where/how you are using them.  For instance:

http://support.sas.com/documentation/cdl/en/ledsoptsref/69751/HTML/default/viewer.htm#p0h5nwbig8mobb...

 

And for outobs:

http://www2.sas.com/proceedings/sugi23/Handson/p130.pdf

 

Super User
Posts: 10,259

Re: OBS AND OUTOBS

Posted in reply to katariasarthak

Maxim 6: Google is your friend.

 

Do a google search each for

 

sas outobs

sas obs

 

and you'll have enough information that will show you the answer.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Solution
‎04-16-2018 01:26 AM
PROC Star
Posts: 266

Re: OBS AND OUTOBS

Posted in reply to katariasarthak

OBS can be a system option or a dataset option, it limits the number of observarions read in a proc or a datastep. OBS normally decides the number of the last observation read. If, however, you have tables with "holes" in them (deleted observations), the results can vary a bit.

Look at this:

data x;
  do i=1 to 10;
    output;
    end;
run;

proc sql; /* delete the first observation */
  delete from x where i=1;
quit;

options obs=5;
data y;
  set x;
run;

data z;
  set x(firstobs=3);
run;

The Y table contains 5 observations, which are i=2 to 6. Because the read started from the beginning, SAS new that an observation was deleted, and adjusted the number to read accordingly.

But the Z table contains 3 observations (as expected), with I values from 3 to 5 (not as expected), because SAS did not read from the start of the table (because of the FIRSTOBS option) ,and therefore did not realize that the first observation was deleted. 

 

The OUTOBS option is ony used in PROC SQL. It can used either in the SQL invocation ("proc SQL OUTOBS=<number>;") or in a RESET Statement. It does not limit the amount of processing done, except that processing stops once the desired number of observations has been output in the statement.

Compare this:

options obs=1;
proc sql;
  select sum(age) from sashelp.class;
quit;
options obs=max;
proc sql outobs=1;
  select sum(age) from sashelp.class;
quit;

The first PROC SQL call will return 14, which is the age of the first person in the dataset (only one record is read). The second SQL call will give you 253, which is the sum of all the ages in the class (OUTOBS does nothing here, as only one sum is to be returned anyway, all the records are read).

☑ This topic is solved.

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

Discussion stats
  • 4 replies
  • 273 views
  • 0 likes
  • 5 in conversation