QUIT;
%MEND;
*******************************************************************************
************************************************;
/*Main Macro that creates the Chunks */
%MACRO InclauseMaker(table=,field=,quote=,chunksize=,outputlib=);
/*Echo the variables passed to the Macro */
%PUT "Table Chosen: &table";
%PUT "Field Chosen: &field";
%PUT "Quote Chosen: "e";
%PUT "Chunksize Chosen: &chunksize";
%PUT "Outputlib Chosen: &outputlib";
/* Validate chosen chunk size is 1 or greater */
%IF %EVAL(&chunksize) <1 %THEN %DO;
%PUT 'Negative or zero chunk sizes are not possible';
%ABORT;
%END;
/*Safety measure to set chunks >1000 to =1000 */
%IF %EVAL(&chunksize) >1000 %THEN %DO;
%PUT 'Setting chunksize to 1000 to prevent sql string
size from exceeding db maximum';
%LET chunksize = 1000;
%END;
/* Check to make sure ID list table exists */
%IF %sysfunc(exist(&table)) %THEN %DO;
%PUT 'The input dataset does exist';
%END;
%ELSE %DO;
%PUT 'The input dataset does not exist';
%ABORT;
%END;
/* Make sure variable exists in the table */
%LET dsid=%SYSFUNC(OPEN(&table));
%LET check=%SYSFUNC(varnum(&dsid.,&field));
%IF &check = 0 %THEN %DO;
%PUT 'Variable does not exist';
%ABORT;
%END;
%ELSE %DO;
%PUT 'Variable does exist';
%END;
/*Get and store number of table observations */
%LET dsid=%SYSFUNC(OPEN(&table));
%LET nobs=%SYSFUNC(ATTRN(&dsid.,NOBS));
%LET rc=%SYSFUNC(CLOSE(&dsid.));
/*If table has no records, abort the process */
%IF &Nobs. EQ 0 %THEN %DO;
%PUT 'There are no records in the dataset.';
%ABORT;
%END;
/*Count how many chunks will be created based on observations and chunksize*/
%PUT "Number of total Chunks: %SYSEVALF(%EVAL(&Nobs)/%EVAL(&chunksize))";
%LET fullchunks=%EVAL(%EVAL(&Nobs)/%EVAL(&chunksize));
%LET remainder=%EVAL(%EVAL(&Nobs)-%EVAL(&fullchunks * &chunksize));