Reputation: 4907
As a follow up to this question, for which my existing answer appears to be best: Extracting sub-data from a SAS dataset & applying to a different dataset
Given a dataset dsn_in
, I currently have a set of macro variables max_1
- max_N
that contain numeric data. I also have a macro variable varlist
containing a list of variables. The two sets of macros are related such that max_1
is associated with scan(&varlist, 1)
, etc. I am trying to do compare the data values within dsn_in
for each variable in varlist
to the associated comparison values max_1
- max_N
. I would like to output the updated data to dsn_out
. Here is what I have so far:
data dsn_out;
set dsn_in;
/* scan list of variables and compare to decision criteria.
if > decision criteria, cap variable */
do i = 1 by 1 while(scan(&varlist, i) ~= '');
if scan("&varlist.", i) > input(symget('max_' || left(put(i, 2.))), best12.) then
scan("&varlist.", i) = input(symget('max_' || left(put(i, 2.))), best12.);
end;
run;
However, I'm getting the following error, which I don't understand. options mprint;
shown. SAS appears to be interpreting scan
as both an array and a variable, when it's a SAS function.
ERROR: Undeclared array referenced: scan.
MPRINT(OUTLIERS_MAX): if scan("var1 var2 var3 ... varN", i) > input(symget('max_'
|| left(put(i, 2.))), best12.) then scan("var1 var2 var3 ... varN", i) =
input(symget('max_' || left(put(i, 2.))), best12.);
ERROR: Variable scan has not been declared as an array.
MPRINT(OUTLIERS_MAX): end;
MPRINT(OUTLIERS_MAX): run;
Any help you can provide would be greatly appreciated.
Upvotes: 0
Views: 524
Reputation: 63424
The specific issue you have here is that you place SCAN on the left side of an equal sign. That is not allowed; SUBSTR is allowed to be used in this fashion, but not SCAN.
Upvotes: 2