12-02-2015 01:40 AM
%macro putlog (varlist=);
%local i nextword;
%do i=1 %to %sysfunc(countw(&varlist));
%let nextword = %scan(&varlist, &i);
this readind the string how can i place the extracted string /word into a new macro variable?
12-02-2015 01:52 AM
12-02-2015 09:26 AM
Since VARLIST is already a macro variable, I guess you want to store the concatenated content of the macro variables in &VARLIST in a new macro variable, say, NAMELIST (which would contain rahul priya in your example). This would require only a minor extension of your macro:
%macro maclist(varlist=); %local i nextword namelist; %let namelist=; %do i=1 %to %sysfunc(countw(&varlist)); %let nextword = %scan(&varlist, &i); %put &nextword = &&&nextword; %let namelist=&namelist &&&nextword; %end; %put &namelist; %mend maclist;
If you wanted to use &NAMELIST outside of the macro, you would have to remove namelist from the %LOCAL statement and use a %GLOBAL namelist; statement instead.
12-04-2015 05:51 AM
12-04-2015 06:06 AM
12-04-2015 07:03 AM
First, don't do it. You already have the values in the list, just use the list.
But if you really need to do it and reference the new variables after the macro ends then you need to do something to make sure the new variables are not defined as local to the macro that is creating them. Adding a %GLOBAL statement is one way.
%macro parselist(varlist); %local i nextvar; %do i=1 %to %sysfunc(countw(&varlist)); %let nextvar=word&i; %global &nextvar; %let &nextvar= %scan(&varlist, &i); %end; %mend parselist; %parselist(A B); %put &word1 &word2;