Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

segmenting datasets into deciles

Status
Not open for further replies.

aybooth

MIS
Feb 6, 2004
9
0
0
US
am i able to segment a dataset of x records into deciles by using the _n_ function? (the dataset is already sorted by the required variable so no further sorting can be done) so that SAS calculates what the last record number is and then divides by 10 and uses that number to create a variable decile populated with 1-10.

thanks
 
You can get the number of records in a data set using the nobs function.

Code:
data _null_;
   set mydataset nobs=count;
   call symput('obscount',trim(left(put(count,10.))));
run;

Play around with this code a bit, the above will do the call statement once for each record in your dataset, you can work it to only run once.

You can then do a little macro code to calculate 1/10th of the number of records, then substitute this in as a macro variable in a subsequent datastep.

Enjoy.
 
Aybooth,
What are you trying to do? The reason I ask is there are many procs that use the 10th 20th percentiles for analysis perhaps you are trying to do the exact same thing that these procs do.

But if you want to know how to split a dataset so that you only are looking at 10% of the data at a time try this.

%macro test(datasetin=,
datasetoutprefix=);
%let m_ = %sysfunc(open(&datasetin));
%let n_ = %sysfunc(attrn(&m_,NOBS));
%let c_ = %sysfunc(close(&m_));

%do i=1 %to %eval(&n_ / 10);
data &datasetoutprefix.&i;
set &datasetin;
if ((&i*10)-11) lt _n_ lt (&i*10);
run;***PUT YOUR CODE HERE FOR MORE PROCESING ***;
%end;

%mend;
%test(datasetin=test,
datasetoutprefix=TEST)
kLAZ
 
Hi,

(1) Using SAS/ACCESS when the data is extracted from oracle data base to SAS what should be the limit of the number of columns? or SAS can handle any number of columns?

(2) Number of columns that an Oracle data base can have?


regards,
sarayu
 
sarayu - I imagine that there IS an upper limit on the number of columns that you can have, but I've never hit it, and I've had tables with more than 100 columns. If you "need" more than that, I would suggest a rethink on what you actually need, as coding to use that many columns will be a bit of a nuisance.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top