%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?
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.
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;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.