BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
deepb
Fluorite | Level 6

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

1 ACCEPTED SOLUTION

Accepted Solutions
Keith
Obsidian | Level 7

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

7 REPLIES 7
manojinpec
Obsidian | Level 7

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

deepb
Fluorite | Level 6

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.

Keith
Obsidian | Level 7

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

deepb
Fluorite | Level 6

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.

Keith
Obsidian | Level 7

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

deepb
Fluorite | Level 6

@Keith,

Apologies, that was my assumption. You are right.

Thanks a lot for the clarification.

VijayRK1
Calcite | Level 5

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

by patient;

run;

 

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

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 14195 views
  • 1 like
  • 4 in conversation