%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= 2018It 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.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.