Hi All, Background: I need a macro to create variable name list. I am using SAS Enterprise Guide 7.1 on Windows Issue: I have issues writing macro variables into a single field. Here is an example: data example ;
input Name $ 8.;
Datalines;
Jake Lin
Mike Lee
Jim Jo
Max Kim
;
run; Before create macro variable name list, I need to transform the space into underscore. My macro as follow: %macro getNmList;
%let namelist=%sysfunc(open(example));
%let NObs=%sysfunc(attrn(&namelist,NOBS));
%syscall set(namelist);
Data TransformedName;
set example;
%do t=1 %to &NObs;
%let rc=%sysfunc(fetchobs(&namelist,&t));
%let Newname=%sysfunc(tranwrd(&name,%str( ),%str(_) ));
%put &Newname;
TranName=&Newname;
%end;
run;
%let namelist=sysfunc(close( namelist ));
%mend;
%getNmList The %put &Newname statement successfully returned my desired output values ( change space to underscore) : Jake_Lin Mike_Lee Jim_Jo Max_Kim However, the output table is not what I expected. The log and output result as follow: (Node: I also notice the datatype for TranName is incorrect but I am not sure why) I would like the result shown as : Attempts: i). I suspect the error happened in this statement : TranName=&Newname; Thus, I tried using TranName=SYMGET('Newname'); But it only returned the last value, and thus, the result TransName field are all Max_Kim. ii). I also tried to re-write the macro using call symputx as follows: data _null_;
set example ;
call symputx(cats('origname',strip(_n_)),Name);
run;
%put &origname1 &origname2 &origname3 &origname4;
/****Log output : Jake Lin Mike Lee Jim Jo Max Kim**********/ %macro transpace;
data _null_;
%do i=1 %to 4;
%let tranName&i =tranwrd(('origname&i'),%str( ),%str(_));
%end;
run;
%mend;
%transpace
%put &tranName1;
/*******Log CANNT get &tranName1 and I having
WARNING: Apparent symbolic reference TRANNAME1 not resolved.*********/ After all the attempts, I am not sure how can I get to my desire name list~~~please help~~~~ Thank you in advance. Vi
... View more