Frage

I'm using SAS 9.2, and I got the following piece of code:

data success error;
length vague 3 path $150;
set foplist;
call symputx('error_count', rownum);
%if &&error&error_count = 0 %then %do;
path= "&&path&error_count";
vague=1;
output success;
%end;
%else %do;
...
%end;
run;

For each record I'd like to get the rownum, and combine it with another macro variable. The rownum displays the rownumber of a record in the foplist dataset. For some reason I always get the last number in the dataset (probably because of macro compilation?)

For example: A --- rownum=1 B --- rownum=2

I only get rownum=2

Any idea how to fix it?

Thanks!

War es hilfreich?

Lösung

You can't create and resolve a macro variable within the same datastep.

Have you already defined the macro variables ERROR1-ERRORx and PATH1-PATHn and wish to retrieve those values into the datastep based on rownum? i.e. to resolve &&ERROR&ERROR_COUNT.

If so, just use symexist / symget...

data success error ;
  length vague 3 path $150 ;
  set foplist ;
  if symexist(cats('ERROR',rownum)) and symexist(cats('PATH',rownum)) then do ;
    error_count = symget(cats('ERROR',rownum)) ;
    if error_count = 0 then do ;
      path = symget(cats('PATH',rownum)) ;
      vague = 1 ;
      output success ;
    end ; 
    else output error ;
  end ;
  else output error ;
run;
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top