<?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 Re: macro loop for non-sequential numbers in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/macro-loop-for-non-sequential-numbers/m-p/496815#M31985</link>
    <description>&lt;P&gt;The best way to do this would be to build a list in a macro variable based on only datasets that exist using a DICTIONARY table:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select memname
into  :data_list separated by ' '
from dictionary.members
where libname = "WORK" and memtype = "DATA"
and substr(memname, 1, 4) = 'CUST' 
;
quit;

%put &amp;amp;data_list;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 19 Sep 2018 03:55:13 GMT</pubDate>
    <dc:creator>SASKiwi</dc:creator>
    <dc:date>2018-09-19T03:55:13Z</dc:date>
    <item>
      <title>macro loop for non-sequential numbers</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/macro-loop-for-non-sequential-numbers/m-p/496808#M31984</link>
      <description>&lt;P&gt;I am trying to do a macro loop for merging datasets with non-sequential names. For example: cust_012011, cust_022011, cust042011.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Unsure as to how I can get the macro loop to work. I have the following at the moment but this stops when there is a no dataset for a particular month:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro combine;
	%local tempTable;
	%do year = &amp;amp;startyr. %to &amp;amp;endyr.;
		%do month = 1 %to 12;
			%let tempTable = cust_data_&amp;amp;year%sysfunc(putn(&amp;amp;month, z2.));

			%if %sysfunc(exist(&amp;amp;temptable)) %then %do;
				Data want_temp_&amp;amp;month.;
					set &amp;amp;tempTable;
					keep cust_no data1;
					rename data1= data1&amp;amp;month.;
				run;	
			%end;
		%end;
	%end;

	data dataset;
	set
		%do i = 1 %to 12;
		want_temp_&amp;amp;i.
		%end;
	;
	by cust_no;
	run;

%mend ombine;
%combine;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 19 Sep 2018 03:17:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/macro-loop-for-non-sequential-numbers/m-p/496808#M31984</guid>
      <dc:creator>eemrun</dc:creator>
      <dc:date>2018-09-19T03:17:15Z</dc:date>
    </item>
    <item>
      <title>Re: macro loop for non-sequential numbers</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/macro-loop-for-non-sequential-numbers/m-p/496815#M31985</link>
      <description>&lt;P&gt;The best way to do this would be to build a list in a macro variable based on only datasets that exist using a DICTIONARY table:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select memname
into  :data_list separated by ' '
from dictionary.members
where libname = "WORK" and memtype = "DATA"
and substr(memname, 1, 4) = 'CUST' 
;
quit;

%put &amp;amp;data_list;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 19 Sep 2018 03:55:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/macro-loop-for-non-sequential-numbers/m-p/496815#M31985</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2018-09-19T03:55:13Z</dc:date>
    </item>
    <item>
      <title>Re: macro loop for non-sequential numbers</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/macro-loop-for-non-sequential-numbers/m-p/496816#M31986</link>
      <description>thanks for this! But still unclear as to how to implement it.</description>
      <pubDate>Wed, 19 Sep 2018 03:58:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/macro-loop-for-non-sequential-numbers/m-p/496816#M31986</guid>
      <dc:creator>eemrun</dc:creator>
      <dc:date>2018-09-19T03:58:59Z</dc:date>
    </item>
    <item>
      <title>Re: macro loop for non-sequential numbers</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/macro-loop-for-non-sequential-numbers/m-p/496819#M31987</link>
      <description>&lt;P&gt;Are you positive you need a macro here?&lt;/P&gt;
&lt;P&gt;It looks like an attempt at a proc transpose in a really long way.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does this get you part of the way there?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _test;
set cust_data_: indsname=source;;
monthV = source;

run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you have any control over your naming convention, SAS works with prefixes so changing the names to be cust_data_YEAR_MONTH would make this a lot more efficient.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/131586"&gt;@eemrun&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I am trying to do a macro loop for merging datasets with non-sequential names. For example: cust_012011, cust_022011, cust042011.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Unsure as to how I can get the macro loop to work. I have the following at the moment but this stops when there is a no dataset for a particular month:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro combine;
	%local tempTable;
	%do year = &amp;amp;startyr. %to &amp;amp;endyr.;
		%do month = 1 %to 12;
			%let tempTable = cust_data_&amp;amp;year%sysfunc(putn(&amp;amp;month, z2.));

			%if %sysfunc(exist(&amp;amp;temptable)) %then %do;
				Data want_temp_&amp;amp;month.;
					set &amp;amp;tempTable;
					keep cust_no data1;
					rename data1= data1&amp;amp;month.;
				run;	
			%end;
		%end;
	%end;

	data dataset;
	set
		%do i = 1 %to 12;
		want_temp_&amp;amp;i.
		%end;
	;
	by cust_no;
	run;

%mend ombine;
%combine;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Sep 2018 04:13:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/macro-loop-for-non-sequential-numbers/m-p/496819#M31987</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-09-19T04:13:32Z</dc:date>
    </item>
    <item>
      <title>Re: macro loop for non-sequential numbers</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/macro-loop-for-non-sequential-numbers/m-p/909673#M44106</link>
      <description>&lt;P&gt;As per &lt;A title="Sample 26155: Loop through a nonsequential list of values with a macro DO loop" href="https://support.sas.com/kb/26/155.html" target="_self"&gt;this&lt;/A&gt; documentation, it seems that it is not possible in SAS to 'Loop through a nonsequential list of values with a macro DO loop'&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;- Dr. Abhijeet Safai&lt;/P&gt;</description>
      <pubDate>Tue, 26 Dec 2023 07:35:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/macro-loop-for-non-sequential-numbers/m-p/909673#M44106</guid>
      <dc:creator>DrAbhijeetSafai</dc:creator>
      <dc:date>2023-12-26T07:35:08Z</dc:date>
    </item>
    <item>
      <title>Re: macro loop for non-sequential numbers</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/macro-loop-for-non-sequential-numbers/m-p/909677#M44107</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/27897"&gt;@DrAbhijeetSafai&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;As per &lt;A title="Sample 26155: Loop through a nonsequential list of values with a macro DO loop" href="https://support.sas.com/kb/26/155.html" target="_self"&gt;this&lt;/A&gt; documentation, it seems that it is not possible in SAS to 'Loop through a nonsequential list of values with a macro DO loop'&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;- Dr. Abhijeet Safai&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Not sure why you're answering on a question from 2018.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you read the note you cite you will also see that it proposes alternative syntax to achieve logically the same - a loop using a distinct list of values.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Dec 2023 09:08:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/macro-loop-for-non-sequential-numbers/m-p/909677#M44107</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2023-12-26T09:08:22Z</dc:date>
    </item>
  </channel>
</rss>

