1
votes

I have a macro variable which stores a string of names, for example:

%let operation = add subtract divide multiply;

I wanted to transpose each element (to appear as observation) in the macro into a data set variable. So the data set should look like:

<obs> <operation>
<1>   add
<2>   subtract
<3>   divide
<4>   multiply
2

2 Answers

4
votes

Use the SCAN() function. The default delimiters will work for your example, otherwise you can specify the exact delimiters to use.

%let operation= add subtract divide multiply;
data want ;
  length obs 8 operation $20 ;
  do obs=1 by 1 until (operation=' ');
    operation=scan("&operation",obs);
    if operation ne ' ' then output;
  end;
run;
2
votes

I still don't know enough about what you have and what you want. This example is contrived but may give you some help regarding syntax etc.

%let operation = add subtract multiply divide;

data operation;
   length &operation 8;
   array operation[*] &operation (2 3 10 4);
   put 'NOTE: ' (operation[*])(=);
   run;

*data set of names;
proc transpose data=operation(obs=0) out=names name=operation;
   var &operation;
   run;
proc print;
   run;