11/12/2023 0 Comments Sas macroNOTE: The data set WORK.CARS_2 has 100 observations and 15 variables. NOTE: The data set WORK.CARS_1 has 100 observations and 15 variables. NOTE: There were 428 observations read from the data set SASHELP.CARS. ***MACRO SPLIT: Splitting into datasets of no more than 100 observations %split (SRC_DATASET=SASHELP.CARS, OUT_PREFIX=WORK.CARS, SPLIT_NUM= 100, SPLIT_DEF=NOBS ) ***MACRO SPLIT: Incorrect SPLIT_DEF=SET value. %split (SRC_DATASET=SASHELP.CARS, OUT_PREFIX=WORK.CARS, SPLIT_NUM= 100, SPLIT_DEF=SET ) The following are examples of the macro invocations: When (_n_ <= &K * &I ) output &OUT_PREFIX._&I * split source dataset into smaller datasets */ * generate list of smaller dataset names */ %if (&K le 0 ) or (&S le 0 ) %then %return * terminate macro if nothing to split */ Put "***MACRO SPLIT: Splitting into &SPLIT_NUM datasets" Įlse put "***MACRO SPLIT: Incorrect SPLIT_DEF=&SPLIT_DEF value. Put "***MACRO SPLIT: Splitting into datasets of no more than &SPLIT_NUM observations" Įlse if upcase ("&SPLIT_DEF" )='SETS' thenĬall symputx ('K',ceil (N/&SPLIT_NUM ) ) * number of observations &K, number of smaller datasets &S */Ĭall symputx ('S',ceil (N/&SPLIT_NUM ) ) ![]() ![]() * SPLIT_DEF - split definition (=SETS or =NOBS ) */ * OUT_PREFIX - prefix of the output data sets */ * SRC_DATASET - name of the source data set */ %macro split (SRC_DATASET=, OUT_PREFIX=, SPLIT_NUM=, SPLIT_DEF= ) Parameter’s SPLIT_DEF value defines the type of scenario (SPLIT_DEF=NOBS means that the source data set is split into several smaller data sets with the number of observations not to exceed SPLIT_NUM value SPLIT_DEF=SETS means that the source data set is split into SPLIT_NUM=value of smaller data sets). Similarly, with the scenario 2, we will split the source data set into several smaller data sets of the same size, but the last smaller data set will have the number of observations equal to the remainder of the division N by K.īelow is a SAS macro code that covers both these scenarios. Therefore, we will split it into several smaller data sets of K observations each, but the last smaller data set will have the number of observations equal to the remainder of the division N by K. Ideally, we would like to split a data set into K observations each, but it is not always possible to do as the quotient of dividing the number of observations in the original dataset N by K is not always going to be a whole number.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |