Dear all,
%let var1=a;
%let var2=b;
%let var3=c;
%let var4=d;
%let var5=e;
%let x= &var1 %to &var5;
i need x=a,b,c,d,e
thank you
Hi,
If you really want to make use of "%to" for larger lists then you'll need to use it inside a macro definition, e.g.:
%let var1=a;
%let var2=b;
%let var3=c;
%let var4=d;
%let var5=e;
%macro makecsv(root,fromval,toval);
%let sep=;
%let makecsv=;
%do csvloop=&fromval %to &toval;
%let makecsv=&makecsv&sep&&&root&csvloop;
%let sep=%str(,);
%end;
&makecsv;
%mend makecsv;
%let x=%makecsv(var,1,5);
%put x=&x;
Regards,
Amir.
Message was edited by: Amir Malik - formatting.
Hi,
If you really want to make use of "%to" for larger lists then you'll need to use it inside a macro definition, e.g.:
%let var1=a;
%let var2=b;
%let var3=c;
%let var4=d;
%let var5=e;
%macro makecsv(root,fromval,toval);
%let sep=;
%let makecsv=;
%do csvloop=&fromval %to &toval;
%let makecsv=&makecsv&sep&&&root&csvloop;
%let sep=%str(,);
%end;
&makecsv;
%mend makecsv;
%let x=%makecsv(var,1,5);
%put x=&x;
Regards,
Amir.
Message was edited by: Amir Malik - formatting.
So there could be many solutions, but do remember SAS Macro is nothing but a text string maneuver.
%let var1=a;
%let var2=b;
%let var3=c;
%let var4=d;
%let var5=e;
%macro cat;
%global x;
%let x=;
%do i=1 %to 5;
%if &i=1 %then %let x=&var1;
%else %let x=&x,&&var&i;
%end;
%mend;
%cat;
%put &x;
Haikuo
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.