%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;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.