%macro combineYears(Year1, Year2, Year3, Year4, Year5);
do year1 to year5;
/*process logic*/
end;
%end;
Yes, but it would be easier if you get rid of the commas between the values. Here's some documentation:
Depends on how you want to use it. You may end up finding that a %DO loop may work just as well.
You can also check out examples 3 and 4 here:
It can be done as follows.
%macro combineYears(Year1, Year2, Year3, Year4, Year5);
%do i=1 %to 5;
%put year= &&year&i;
/*process logic*/
%end;
%mend combineYears;
%combineYears(2000, 2001, 2010, 2015, 2018);
*LOG
year= 2000
year= 2001
year= 2010
year= 2015
year= 2018
It will be good if you also pass the number of years you are passing and use to loop control.
Please let us know if it helped.
@Satish_Parida your approach, while it will work would have issues if the user only wants to process 2 years and would require a diffent macro to process any different number of year.
This is what @Astounding meant by getting rid of commas:
%macro combineYears(YearList); %do i=1 %to %sysfunc(countw(&yearlist)); %put year= %scan(&yearlist,&i); /*process logic*/ %end; %mend combineYears; %combineYears(2000 2001 2010 2015 2018);
which will process any explicit list of one or more items. Note that we have no check for and empty list though nothing inside the %do loop will happen so likely okay for that, or checks to ensure that the values in the list are valid for any other purpose.
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.