Hey folks
Some of my continuous variables have default values that signify various things to the owners of the data. The problem is that the default values are extremes which skew my means calculation so I need to remove these.
This is easily done by listing the defaults in a field (comma separated with a char type) on my control table and using an array to process this. Code as below
*Count the number of default values for each variable;
data defs1;
set control.continuous_vars (where=(chlist="&chlist"));
if default ne '' then do;
noofcoms = count(default,",")+1;
end;
else noofcoms=0;
run;
*Find the maximum number of default values for this data source as this defines the size of the array;
proc sql;
select max(noofcoms) into :numdef
from defs1;
quit;
%let numdef = &numdef;
%put Max no. of unique default values = &numdef;
%if &numdef gt 0 %then %do;
*Create an array for each variable -
- use this to decide whether the variable is a default value.
- create a new column to count the number of default values.
- set the value of the var to null if there is a default value so that this does not skew the means.
- if a default value is found stop the array from processing so that values are not overwritten and to save resource.;
data defs (drop=g _temporary_ val:);
retain defs_1-defs_&ww 0;
set work.this_month_&chlist;
%do v=1 %to &ww;
%if &&default_&v ne %then %do;
array defaults_&v._ val1-val&numdef. _temporary_;
do g = 1 to &numdef.;
defaults_&v._{g} = scan("&&default_&v",g,",");
if defaults_&v._{g} = &&varname_&v then do;
defs_&v = 1;
&&varname_&v=.;
goto complete_&v;
end;
end;
complete_&v:
%end;
%end;
run;
%end;
The problem comes in if the default value is a negative as SAS then sees this as a character and not a number and errors. If I put a %eval around the default value (&&default_&v) it errors if it is null as the macro variable does not exist. How can I get around this