0

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.

Community
  • 1
  • 1
alexwhitworth
  • 4,839
  • 5
  • 32
  • 59
  • I'll reiterate what I said in my earlier answer. You are better off not using macro variables this way. Keep data in datasets, and use the very, very powerful tools available to you in SAS for manipulating those datasets. – Joe Mar 28 '13 at 20:30
  • @Joe I'm not sure what "very, very powerful tools available" you're referring to. If you have time to update your prior response, I would greatly appreciate it. – alexwhitworth Mar 28 '13 at 21:21

1 Answers1

2

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.

Joe
  • 62,789
  • 6
  • 49
  • 67