Place to learn SAS and enhance your professional career...
Usage of the Macro-
%splitdsnbyobs(DatasetName, No ofobservation to split by)
%RecsInDS(&dsn,no_obs); /* Read more about this macro at http://sastechies.blogspot.com/2009/11/ways-to-count-number-of-obs-in-dataset.html */
/*calculate the final obs for each do loop iteration*/
%if %sysfunc(ceil(%eval(&i * &splitby.))) gt &no_obs %then &no_obs;
%else %sysfunc(ceil(%eval(&i * &splitby.)));
/* keep the observations from firstobs= and obs=*/
%do i=1 %to %sysfunc(ceil(&no_obs/&splitby));
set &dsn (firstobs=%sysfunc(floor(%eval((&i.-1)*&splitby.+1))) obs=%finalobs);
/* Eg. Create a Dsn with 101 observations */
do i=1 to 101;
options symbolgen mprint;
/*Now call the macro to split the observations every 20 records*/
Is there a macro to split a dataset to multiple datasets vertically with a common primary key. For eg, a dataset has 400 fields and 20,000 records. If we can split the dataset into two, with 200 fields and 20,000 records in each dataset with a common field like loan number as primary key would be helpful to load the details for analysis.ThanksKrishnan
Note: Only a member of this blog may post a comment.