I'm trying to reproduce the code found here, specifically on page 7: http://www.nesug.org/proceedings/nesug04/pm/pm13.pdf
/* set up example*/
%let var_1 = 'abc';
%let var_2 = 'def';
%let var_3 = 'ghi';
%let val_1 = 1.5;
%let val_2 = 3;
%let val_3 = 4.5;
/* use symget to create a list of var names and values */
data scores;
length var_name $32 value 8.;
do _N_ = 1 to 3;
var_name = symget('var_' || left(_N_));
value = symget('val_' || left(_N_));
end;
run;
However, the end result that I'm getting is only the last variable, not all 3:
var_name value
ghi 4.5
I want:
var_name value
abc 1.5
def 3
ghi 4.5
Why isn't this working?
You are missing an output
statement to write each row. Insert it here:
do _N_ = 1 to 3;
var_name = symget('var_' || left(_N_));
value = symget('val_' || left(_N_));
output;
end;