diff --git a/all.sas b/all.sas index 93df8ed..e8a1427 100644 --- a/all.sas +++ b/all.sas @@ -994,12 +994,12 @@ or %index(&pgm,/tests/testteardown) @brief Returns an unused libref @details Use as follows: - libname mclib0 (work); - libname mclib1 (work); - libname mclib2 (work); + libname mclib0 (work); + libname mclib1 (work); + libname mclib2 (work); - %let libref=%mf_getuniquelibref(); - %put &=libref; + %let libref=%mf_getuniquelibref(); + %put &=libref; which returns: @@ -1148,33 +1148,50 @@ or %index(&pgm,/tests/testteardown) @file @brief Returns number of variables in a dataset @details Useful to identify those renagade datasets that have no columns! + Can also be used to count for numeric, or character columns - %put Number of Variables=%mf_getvarcount(sashelp.class); + %put Number of Variables=%mf_getvarcount(sashelp.class); + %put Character Variables=%mf_getvarcount(sashelp.class,typefilter=C); + %put Numeric Variables = %mf_getvarcount(sashelp.class,typefilter=N); returns: > Number of Variables=4 - @param libds Two part dataset (or view) reference. + + @param [in] libds Two part dataset (or view) reference. + @param [in] typefilter= (A) Filter for certain types of column. Valid values: + @li A Count All columns + @li C Count Character columns only + @li N Count Numeric columns only @version 9.2 @author Allan Bowe **/ -%macro mf_getvarcount(libds +%macro mf_getvarcount(libds,typefilter=A )/*/STORE SOURCE*/; - %local dsid nvars rc ; + %local dsid nvars rc outcnt x; %let dsid=%sysfunc(open(&libds)); %let nvars=.; + %let outcnt=0; + %let typefilter=%upcase(&typefilter); %if &dsid %then %do; %let nvars=%sysfunc(attrn(&dsid,NVARS)); + %if &typefilter=A %then %let outcnt=&nvars; + %else %if &nvars>0 %then %do x=1 %to &nvars; + /* increment based on variable type */ + %if %sysfunc(vartype(&dsid,&x))=&typefilter %then %do; + %let outcnt=%eval(&outcnt+1); + %end; + %end; %let rc=%sysfunc(close(&dsid)); %end; %else %do; %put unable to open &libds (rc=&dsid); %let rc=%sysfunc(close(&dsid)); %end; - &nvars + &outcnt %mend mf_getvarcount;/** @file @brief Returns the format of a variable @@ -2203,7 +2220,12 @@ Usage: or "&SYSPROCESSNAME "="Compute Server " or &mode=INCLUDE %then %do; - options obs=max replace nosyntaxcheck mprint; + options obs=max replace mprint; + %if "%substr(&sysver,1,1)" ne "4" and "%substr(&sysver,1,1)" ne "5" + %then %do; + options nosyntaxcheck; + %end; + %if &mode=INCLUDE %then %do; %if %sysfunc(exist(&errds))=1 %then %do; data _null_; @@ -7458,6 +7480,7 @@ create table &outsummary as