<?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: Dynamic dataset name from macro loop in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-dataset-name-from-macro-loop/m-p/470855#M285645</link>
    <description>"Why all that complicated and unnessecary macro code?" - Maybe, because call execute statements are hardly readable and thus difficult to debug. But since &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt; posted the important hint: don't split data, it hardly matters how crappy the code is.</description>
    <pubDate>Sun, 17 Jun 2018 07:59:14 GMT</pubDate>
    <dc:creator>error_prone</dc:creator>
    <dc:date>2018-06-17T07:59:14Z</dc:date>
    <item>
      <title>Dynamic dataset name from macro loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-dataset-name-from-macro-loop/m-p/470445#M285640</link>
      <description>&lt;P&gt;Hi --&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm trying to run a macro which will loop through each value of a date in a dataset. In the below example I have 6 dates that I want to pass through a loop. I want the macro to output 6 datasets with the SAS date value added to the end of the dataset name.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example - the dates table looks like this:&lt;/P&gt;
&lt;P&gt;21185&lt;BR /&gt;21216&lt;BR /&gt;21244&lt;BR /&gt;21275&lt;BR /&gt;21305&lt;BR /&gt;21336&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want output datasets called:&lt;/P&gt;
&lt;P&gt;test_21185&lt;/P&gt;
&lt;P&gt;test_21216&lt;/P&gt;
&lt;P&gt;..etc&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For some reason I cannot pass the date value to the dataset name highlighted in red text below. I do not want to use a call execute for this -- has to do with some compilation time/execution time nuances for my actual application.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*Create a dataset with dates to be used for a loop*/
data work.t0;
LOOK_AT_MTH="01JAN2018"d;
do while (LOOK_AT_MTH&amp;lt;="01JUN2018"d);
    output;
	LOOK_AT_MTH=intnx('month', LOOK_AT_MTH, 1, 's');
end;
run;

/*put dates into a macro variable pipe delimited*/
proc sql noprint;
    select distinct LOOK_AT_MTH into :dates separated by '|'
    from work.t0;
quit;

/*macro to loop throgh each date value -- I want the output to be test_21185, test_21216, etc...*/
%macro runloop;
%do i=1 %to %sysfunc(countw(%superq(dates),|));
	%let dsname=%qscan(%superq(dates),&amp;amp;i,|);
  	data test_&lt;FONT color="#FF0000"&gt;&amp;amp;dsname.&lt;/FONT&gt;;
	date=%qscan(%superq(dates),&amp;amp;i,|);
	run;
%end;
%mend runloop;

%runloop;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 14 Jun 2018 20:41:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-dataset-name-from-macro-loop/m-p/470445#M285640</guid>
      <dc:creator>mdavidson</dc:creator>
      <dc:date>2018-06-14T20:41:00Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic dataset name from macro loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-dataset-name-from-macro-loop/m-p/470453#M285641</link>
      <description>&lt;P&gt;It's a little bit of a guess, since we have no log, no diagnostics, and just the clue that the process breaks down somewhere between the beginning and the end.&amp;nbsp; So with that to work with ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You are quoting things that don't need to be quoted.&amp;nbsp; Get rid of %superq, change %qscan to %scan, and try it this way:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN class="token macrobound"&gt;%macro&lt;/SPAN&gt; runloop&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN class="token macrostatement"&gt;%do&lt;/SPAN&gt; i&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;1&lt;/SPAN&gt; &lt;SPAN class="token macrostatement"&gt;%to&lt;/SPAN&gt; &lt;SPAN class="token macrostatement"&gt;%sysfunc&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;countw&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&amp;amp;&lt;/SPAN&gt;dates&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;|&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &lt;SPAN class="token macroname"&gt;%let&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;dsname&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token macroname"&gt;%scan&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&amp;amp;&lt;/SPAN&gt;dates&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;i&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;| |&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt; test_&lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;dsname&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;SPAN class="token function"&gt;date&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&amp;amp;dsname&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &lt;SPAN class="token procnames"&gt;run&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN class="token macrostatement"&gt;%end&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN class="token macrobound"&gt;%mend&lt;/SPAN&gt; runloop&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also note, using | as a delimiter can cause trouble depending on where the | is used by macro language.&amp;nbsp; It is another way of saying "or" which can be interpreted as the logical "or" depending on usage.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Jun 2018 21:10:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-dataset-name-from-macro-loop/m-p/470453#M285641</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-06-14T21:10:57Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic dataset name from macro loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-dataset-name-from-macro-loop/m-p/470455#M285642</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.t0;
LOOK_AT_MTH="01JAN2018"d;
do while (LOOK_AT_MTH&amp;lt;="01JUN2018"d);
    output;
	LOOK_AT_MTH=intnx('month', LOOK_AT_MTH, 1, 's');
end;
run;

/*put dates into a macro variable pipe delimited*/
proc sql noprint;
    select distinct LOOK_AT_MTH into :dates separated by '|'
    from work.t0;
quit;

/*macro to loop throgh each date value -- I want the output to be test_21185, test_21216, etc...*/
%macro runloop;
%do i=1 %to %sysfunc(countw(%superq(dates),|));
	%let dsname=%sysfunc(compress(%qscan(%superq(dates),&amp;amp;i,|)));
  	data test_&amp;amp;dsname.;
    date=&amp;amp;dsname;
	run;
	%put &amp;amp;dsname;
%end;
%mend runloop;

%runloop;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 14 Jun 2018 21:08:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-dataset-name-from-macro-loop/m-p/470455#M285642</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-06-14T21:08:38Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic dataset name from macro loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-dataset-name-from-macro-loop/m-p/470494#M285643</link>
      <description>&lt;P&gt;The consensus is generally, don't do this.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://www.sascommunity.org/wiki/Split_Data_into_Subsets" target="_blank"&gt;http://www.sascommunity.org/wiki/Split_Data_into_Subsets&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you insist, there are several approaches outlined in the steps above or in the blog post below. One of the examples in the blog also does dynamic naming.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://blogs.sas.com/content/sasdummy/2015/01/26/how-to-split-one-data-set-into-many/" target="_blank"&gt;https://blogs.sas.com/content/sasdummy/2015/01/26/how-to-split-one-data-set-into-many/&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Jun 2018 01:02:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-dataset-name-from-macro-loop/m-p/470494#M285643</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-06-15T01:02:58Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic dataset name from macro loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-dataset-name-from-macro-loop/m-p/470531#M285644</link>
      <description>&lt;P&gt;Why all that complicated and unnessecary macro code?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.t0;
LOOK_AT_MTH="01JAN2018"d;
do while (LOOK_AT_MTH&amp;lt;="01JUN2018"d);
    output;
	LOOK_AT_MTH=intnx('month', LOOK_AT_MTH, 1, 's');
end;
run;

data _null_;
set work.t0;
call execute('
  data test_' !! put(look_at_mth,z5.) !! ';
  date=' !! put(look_at_mth,z5.) !! ';
  run;
');
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 15 Jun 2018 09:15:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-dataset-name-from-macro-loop/m-p/470531#M285644</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-06-15T09:15:47Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic dataset name from macro loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-dataset-name-from-macro-loop/m-p/470855#M285645</link>
      <description>"Why all that complicated and unnessecary macro code?" - Maybe, because call execute statements are hardly readable and thus difficult to debug. But since &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt; posted the important hint: don't split data, it hardly matters how crappy the code is.</description>
      <pubDate>Sun, 17 Jun 2018 07:59:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-dataset-name-from-macro-loop/m-p/470855#M285645</guid>
      <dc:creator>error_prone</dc:creator>
      <dc:date>2018-06-17T07:59:14Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic dataset name from macro loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-dataset-name-from-macro-loop/m-p/471204#M285646</link>
      <description>This is excellent and worked great for me, thank you for taking the time to come up with some great code!</description>
      <pubDate>Mon, 18 Jun 2018 19:26:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-dataset-name-from-macro-loop/m-p/471204#M285646</guid>
      <dc:creator>mdavidson</dc:creator>
      <dc:date>2018-06-18T19:26:29Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic dataset name from macro loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-dataset-name-from-macro-loop/m-p/471206#M285647</link>
      <description>&lt;P&gt;Thank you for your input, I agree with you. In general it is best to just use BY group processing. However, in my case I'm taking datasets and running some Enterprise Miner functions on them so I don't have that option available to me. I'm scoring data based on "as of" dates -- so splitting in my case was the obvious choice for me.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Jun 2018 19:29:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-dataset-name-from-macro-loop/m-p/471206#M285647</guid>
      <dc:creator>mdavidson</dc:creator>
      <dc:date>2018-06-18T19:29:31Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic dataset name from macro loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-dataset-name-from-macro-loop/m-p/471216#M285648</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16552"&gt;@mdavidson&lt;/a&gt;&amp;nbsp;Most welcome. I am glad &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Jun 2018 19:48:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-dataset-name-from-macro-loop/m-p/471216#M285648</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-06-18T19:48:47Z</dc:date>
    </item>
  </channel>
</rss>

