12-07-2015 05:55 AM
A macro that identifies any variables either character or numeric – for which all of the observations are missing values. When this occurs, a warning message is output to the SAS log.
%macro vtype(dsname=, varname=, outputflag=);
%if %sysfunc(exist(&dsname)) %then %do;
%let dsid = %sysfunc(open(&dsname));
%let varnum = %sysfunc(varnum(&dsid,&varname));
%let vartyp = %sysfunc(vartype(&dsid,&varnum));
%if &vartyp = C %then %do;
%else %if &vartyp = N %then %do;
%else %put "DSNAME parameter is invalid Please pass appropriate values.";
this my code how can i change it according to my requirment?
12-07-2015 07:10 AM
You can check for missing values using proc sql:
proc sql noprint;
select max(&varname) into :max_value from &dsname;
and afterwards just check the value of the newly created macro variable:
%if &max_value= or &max_value=. %then %do; %put &varname has only missing values;%end;
12-07-2015 08:56 AM
It's extremely unlikely that missing values could cause a problem. Here are two other situations that are more likely candidates.
(1) Even if DSNAME does not exist, your macro still attempts to extract VARNUM to identify the position of VARNAME.
(2) If DSNAME exists but does not contain VARNAME, your macro still attempts to extract whether VARNAME is numeric or character.
I would be shocked if SAS even examines the values of VARNAME. The problem almost certainly lies elsewhere.