简体   繁体   中英

macro variable as numeric inside data step

I am asking for a little help. link where is question In above post I have little problem set dynamic variable which I will count used columns. How I can do it?

data want;
  set have;
  array V varr1-varr3;
 call SYMPUTN('countxxx',dim(V)) /* here I try set numeric*/
  array L[&countxxx.] _temporary_;/* here input numeric*/

  * save first rows values in temporary array for use in other rows;
  if _n_ = 1 then 
    do index = 1 to dim(V);
      L[index] = V[index];
    end;

  * … for example … ;

  array delta_from_1st [&countxxx.];  * array statement implicitly creates three new variables that become part of PDV and get output;
  do index = 1 to dim(V);
    delta_from_1st[index] = V[index] - L[index];
  end;      
run;

It is not a character vs numeric issue. All macro variables are character, but since your value is all digits the SAS compiler will interpret the text it generates as a number since you are not enclosing it in quotes.

The real issue is that you are trying to reference the macro variable COUNTXXX before you have created it. The macro references are resolved before the data step starts running. Split your step into two steps.

data _null_;
  set have;
  array V varr:;
  call SYMPUTX('countxxx',dim(V)) ;
  stop;
run;

data want;
  set have;
  array L[&countxxx.] _temporary_;
...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM