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
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
Hi Obs can onl be used when creating the dataset using datastep
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.
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
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.
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
@Keith,
Apologies, that was my assumption. You are right.
Thanks a lot for the clarification.
proc sort data=demo(firstobs=3 obs=5) out=demo9;
by patient;
run;
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: