SAS variable concatenation through data step -


i looking way create string variable containing values of dataset while going through data step.

example data set work.test:

addtostringyn    value      y           1      y           2      n           3      y           4      n           5 

so in end, variable like: onetwofour (or better fourtwoone). looks simple, can't seem find way it. tried work macro variables this:

%let stringvar=; data _null_;   set work.test;   if addtostringyn = "y" do;     call symput('stringvar',"&stringvar" || strip(value));   end; run; 

but gives:

global stringvar 4 

so last value. must because of misunderstanding of mine macro facility, don't understand why there last value in variable. thought last time symput called executed or something, when adjust code to:

%let stringvar=; data _null_;   set work.test;   if addtostringyn = "y" do;     call symput('stringvar'||strip(value),"&stringvar" || strip(value));   end; run; 

then them all:

global stringvarone  1 global stringvartwo  2 global stringvarfour  4 

so last guess going through data step, 'call symput...' line added macro processor "&stringvar" replaced , after final statement executed.
is assumption or there explanation? , original question: there easy way achieve (having desired variable)?

greetings seems simple enough, here solution:

data a; set test end=eof; length cat $100.; retain cat; if addtostringyn = "y" do;    cat=trim(left(cat))||trim(left(value)); end; if eof do;    call symput("var",cat);    output; end; run;  %put var=&var; 

in example have concatenation of variable in dataset in column "cat" , have macrovariable var same list


Comments