Hello,
I have a list of data sets that follow the same naming convention: map_data_1718, map_data_1617, map_data_1516 . . . , map_data_0203. The below loop works for reading in and creating working data sets for all the raw data sets in the list:
%macro iterm(lst);
%local finish;
%local i;
%local year;
%let finish=%sysfunc(countw(&lst));
%do i = 1 %to &finish;
%let year=%scan(&lst,&i);
proc import datafile="&maindir.\map_data_&year..csv"
out=work.over12_&year.
dbms=csv
replace;
run;
%end;
%mend iterm;
%iterm(1718 1617 1516 1415 1314 1213 1112 1011 0910 0809 0708 0607 0506 0405 0304 0203)
However, there are actually more data sets than this. Not only are there the "map_data_XXXX" data sets, but there are map12to17_XXXX and map18older_XXXX data sets. All sets of data sets follow the same numeric year suffix pattern. So I am hoping to have a loop within a loop that reads in ALL the data sets. That is, for each prefix in map_data, map12to17, map18older AND for each year in 1718, 1617, . . . 0203, read-in and create a working data set. Specifically, the data set are map_data_1718, map_data_1617 . . . map_data_0203; map12to17_1718, map12to17_1617 . . . map12to17_0203; map18older1718, map18older1617 . . . map18older0203.
I am newish to SAS and can't seem to figure out how to get the loop within a loop thing to work. Below is my attempt:
%macro jterm(list);
%local fin;
%local j;
%local prefix;
%let fin=%sysfunc(countw(&list));
%do j = 1 %to &fin;
%let prefix=%scan(&list,&j);
%macro iterm(lst);
%local finish;
%local i;
%local year;
%let finish=%sysfunc(countw(&lst));
%do i = 1 %to &finish;
%let year=%scan(&lst,&i);
proc import datafile="&maindir.\&prefix._&year..csv"
out=work.over12_&year.
dbms=csv
replace;
run;
%end;
%mend iterm;
%end;
%mend jterm;
%iterm(1718 1617 1516 1415 1314 1213 1112 1011 0910 0809 0708 0607 0506 0405 0304 0203)
%jterm(map_data map12to17 map18older)
... View more