<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Loop within loop with macro list in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Loop-within-loop-with-macro-list/m-p/689180#M209482</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;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:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%macro iterm(lst);
	%local finish;
	%local i;
	%local year;
	%let finish=%sysfunc(countw(&amp;amp;lst));
		%do i = 1 %to &amp;amp;finish;
		%let year=%scan(&amp;amp;lst,&amp;amp;i);
			proc import datafile="&amp;amp;maindir.\map_data_&amp;amp;year..csv"
				out=work.over12_&amp;amp;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)&lt;/PRE&gt;
&lt;P&gt;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 . . .&amp;nbsp;map12to17_0203; map18older1718, map18older1617 . . .&amp;nbsp; map18older0203.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;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:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%macro jterm(list);
	%local fin;
	%local j;
	%local prefix;
	%let fin=%sysfunc(countw(&amp;amp;list));
		%do j = 1 %to &amp;amp;fin;
		%let prefix=%scan(&amp;amp;list,&amp;amp;j);

%macro iterm(lst);
	%local finish;
	%local i;
	%local year;
	%let finish=%sysfunc(countw(&amp;amp;lst));
		%do i = 1 %to &amp;amp;finish;
		%let year=%scan(&amp;amp;lst,&amp;amp;i);
			proc import datafile="&amp;amp;maindir.\&amp;amp;prefix._&amp;amp;year..csv"
				out=work.over12_&amp;amp;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)&lt;/PRE&gt;</description>
    <pubDate>Tue, 06 Oct 2020 13:14:46 GMT</pubDate>
    <dc:creator>raivester</dc:creator>
    <dc:date>2020-10-06T13:14:46Z</dc:date>
    <item>
      <title>Loop within loop with macro list</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-within-loop-with-macro-list/m-p/689180#M209482</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;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:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%macro iterm(lst);
	%local finish;
	%local i;
	%local year;
	%let finish=%sysfunc(countw(&amp;amp;lst));
		%do i = 1 %to &amp;amp;finish;
		%let year=%scan(&amp;amp;lst,&amp;amp;i);
			proc import datafile="&amp;amp;maindir.\map_data_&amp;amp;year..csv"
				out=work.over12_&amp;amp;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)&lt;/PRE&gt;
&lt;P&gt;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 . . .&amp;nbsp;map12to17_0203; map18older1718, map18older1617 . . .&amp;nbsp; map18older0203.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;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:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%macro jterm(list);
	%local fin;
	%local j;
	%local prefix;
	%let fin=%sysfunc(countw(&amp;amp;list));
		%do j = 1 %to &amp;amp;fin;
		%let prefix=%scan(&amp;amp;list,&amp;amp;j);

%macro iterm(lst);
	%local finish;
	%local i;
	%local year;
	%let finish=%sysfunc(countw(&amp;amp;lst));
		%do i = 1 %to &amp;amp;finish;
		%let year=%scan(&amp;amp;lst,&amp;amp;i);
			proc import datafile="&amp;amp;maindir.\&amp;amp;prefix._&amp;amp;year..csv"
				out=work.over12_&amp;amp;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)&lt;/PRE&gt;</description>
      <pubDate>Tue, 06 Oct 2020 13:14:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-within-loop-with-macro-list/m-p/689180#M209482</guid>
      <dc:creator>raivester</dc:creator>
      <dc:date>2020-10-06T13:14:46Z</dc:date>
    </item>
    <item>
      <title>Re: Loop within loop with macro list</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-within-loop-with-macro-list/m-p/689202#M209486</link>
      <description>&lt;P&gt;Nested macros is rarely if ever a good idea. Nested loops ought to work just fine. This code is untested, but it should give you the idea.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro loop(list1,list2);
	%let fin=%sysfunc(countw(&amp;amp;list1));
	%let finish=%sysfunc(countw(&amp;amp;list2));
    %do j = 1 %to &amp;amp;fin;
		%let prefix=%scan(&amp;amp;list1,&amp;amp;j);
		%do i = 1 %to &amp;amp;finish;
		    %let year=%scan(&amp;amp;list2,&amp;amp;i);
			proc import datafile="&amp;amp;maindir.\&amp;amp;prefix._&amp;amp;year..csv"
				out=work.over12_&amp;amp;year.
				dbms=csv
				replace;
			run;  
		%end;
    %end;
%mend loop;

%loop(map_data map12to17 map18older,1718 1617 1516 1415 1314 1213 1112 1011 0910 0809 0708 0607 0506 0405 0304 0203)&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 06 Oct 2020 13:37:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-within-loop-with-macro-list/m-p/689202#M209486</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-10-06T13:37:33Z</dc:date>
    </item>
    <item>
      <title>Re: Loop within loop with macro list</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-within-loop-with-macro-list/m-p/689204#M209487</link>
      <description>&lt;P&gt;Make it with 1 macro and two loops:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro jterm(list, lst);
	%local fin;
	%local j;
	%local prefix;
	%let fin=%sysfunc(countw(&amp;amp;list));
		%do j = 1 %to &amp;amp;fin;
		%let prefix=%scan(&amp;amp;list,&amp;amp;j);

    	%local finish;
    	%local i;
    	%local year;
    	%let finish=%sysfunc(countw(&amp;amp;lst));
    		%do i = 1 %to &amp;amp;finish;
    		%let year=%scan(&amp;amp;lst,&amp;amp;i);
    			proc import datafile="&amp;amp;maindir.\&amp;amp;prefix._&amp;amp;year..csv"
    				out=work.over12_&amp;amp;year.
    				dbms=csv
    				replace;
    			run;  
    		%end;

%end;

%mend jterm;

options mprint;
%jterm(1718 1617, map_data map12to17)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;All the best&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Tue, 06 Oct 2020 13:36:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-within-loop-with-macro-list/m-p/689204#M209487</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2020-10-06T13:36:04Z</dc:date>
    </item>
  </channel>
</rss>

