Help using Base SAS procedures

Basic Question on Obs= in proc sort

Accepted Solution Solved
Reply
New Contributor
Posts: 4
Accepted Solution

Basic Question on Obs= in proc sort

Hi,

I was just going through something and realized a strange usage of Obs dataset option.

I was under an impression that OBS=option can be used anywhere with dataset to limit the number of observation but it proved wrong

Consider below example:

data test;
input a ;
datalines;
1
2
3
4
1
3
45
26
34
;
run;

proc sort data=test  out= test1(obs=3) nodupkey;
by a;
run;

In the above code, Obs=3 doesnt limit the number of observations. Can someone please highlight the reason of it as it is really strange for me being beginner in SAS?

Logs below:

37 data test;

38 input a ;

39 datalines;

NOTE: The data set WORK.TEST has 9 observations and 1 variables.

NOTE: DATA statement used (Total process time):

real time 0.01 seconds

cpu time 0.00 seconds

49 ;

50 run;

51

52 proc sort data=test out= test1 (obs=3) nodupkey;

53 by a;

54 run;

NOTE: There were 9 observations read from the data set WORK.TEST.

NOTE: 2 observations with duplicate key values were deleted.

NOTE: The data set WORK.TEST1 has 7 observations and 1 variables.

NOTE: PROCEDURE SORT used (Total process time):

real time 0.03 seconds

cpu time 0.03 seconds


Accepted Solutions
Solution
‎02-28-2012 07:08 AM
Regular Contributor
Posts: 151

Basic Question on Obs= in proc sort

Hi @deepb,

Have you definitely tried using OBS= against the output dataset, because it certainly doesn't work for me.

e.g. the following code

data class (obs=5);

set sashelp.class;

run;

This creates a log entry that shows "WARNING 70-63: The option OBS is not valid in this context.  Option ignored."

The SAS documentation also states it is restricted to input datasets only

http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000131154.htm

View solution in original post


All Replies
Frequent Contributor
Posts: 138

Basic Question on Obs= in proc sort

Hi Obs can onl be used when creating the dataset using datastep

New Contributor
Posts: 4

Basic Question on Obs= in proc sort

Hi Manoj,

I disagree. OBS option can also be used in procedures for limiting the number of observations.

Like In above example in proc sort, i can use obs=option in data=test but it doesnt work with the dataset in out=:

It works here:

proc sort data=test(obs=3)  out=test1 nodupkey;
by a;
run;

It doesnt work here:

proc sort data=test  out= test1(obs=3) nodupkey;
by a;
run;

so my question is still open.. why obs=option doesnt work with out=test1 dataset.

Regular Contributor
Posts: 151

Basic Question on Obs= in proc sort

Hi @deepb,

OBS= can only be used against the dataset being read in, not the output dataset, this can be in a procedure or datastep.

In PROC SQL you can use the OUTOBS= option to restrict the number of observations in the output dataset.

Regards,

Keith

New Contributor
Posts: 4

Basic Question on Obs= in proc sort

Hi Keith,

With ref to your reply "OBS= can only be used against the dataset being read in, not the output dataset, this can be in a procedure or datastep."

It may be true for proc but its not true for datastep.

In datastep, you can use OBS= on output datset like this:

Data x(obs=3);

set test;

run;

Output dataset X will keep only 3 rows in it.

I hope it sounds logical.

I am still looking for the reason why OBS= doesnt work in below example:

proc sort data=test  out= test1(obs=3) nodupkey;
by a;
run;

Please advise.

Solution
‎02-28-2012 07:08 AM
Regular Contributor
Posts: 151

Basic Question on Obs= in proc sort

Hi @deepb,

Have you definitely tried using OBS= against the output dataset, because it certainly doesn't work for me.

e.g. the following code

data class (obs=5);

set sashelp.class;

run;

This creates a log entry that shows "WARNING 70-63: The option OBS is not valid in this context.  Option ignored."

The SAS documentation also states it is restricted to input datasets only

http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000131154.htm

New Contributor
Posts: 4

Basic Question on Obs= in proc sort

@Keith,

Apologies, that was my assumption. You are right.

Thanks a lot for the clarification.

Occasional Learner
Posts: 1

Re: Basic Question on Obs= in proc sort

proc sort data=demo(firstobs=3 obs=5) out=demo9;

by patient;

run;

 

Ref: http://www2.sas.com/proceedings/sugi31/030-31.pdf

☑ This topic is solved.

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

Discussion stats
  • 7 replies
  • 4001 views
  • 0 likes
  • 4 in conversation