<?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: Automate the Creation of Datasets w/ Macro Program in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Automate-the-Creation-of-Datasets-w-Macro-Program/m-p/355626#M83289</link>
    <description>&lt;P&gt;&lt;SPAN&gt;Because I have issues understanding %DO %TO as well as %DO %UNTIL and wanted to learn it more organically from being able to do it through a do loop from a real life example. &amp;nbsp;Of course there are more efficient ways which I will be implementing in the final program, but wanted to know how to do it this way. &lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 03 May 2017 14:40:31 GMT</pubDate>
    <dc:creator>eparson</dc:creator>
    <dc:date>2017-05-03T14:40:31Z</dc:date>
    <item>
      <title>Automate the Creation of Datasets w/ Macro Program</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Automate-the-Creation-of-Datasets-w-Macro-Program/m-p/355373#M83226</link>
      <description>&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;DIV class="vote"&gt;&lt;BR /&gt;&lt;DIV class="favoritecount"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/TD&gt;&lt;TD&gt;&lt;DIV class="post-text"&gt;&lt;P&gt;I am looking to create multiple datasets from city_variables dataset. There are a total of 58 observations that I summed up into macrovariable (&amp;amp;count) to stop the do loop.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The city_variables dataset looks like (vertically ofcourse):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;CITY_NAME
City1
City2
City3
City4
City5
City6
City7
City8
City9
City10&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;..........&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;City58&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I created macrovariable &amp;amp;name from a data &lt;EM&gt;null&lt;/EM&gt; statement in order to input the cityname into the dataset name.&lt;/P&gt;&lt;P&gt;Any help would be great on how to automate the creation of the 48 files by name (not number). Thanks again.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/&lt;EM&gt;Create macro with number of observations in concordinate file&lt;/EM&gt;/&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;proc sql;
select count(area_name);
into :count
from main.state_all;
quit;


%macro repeat;
data _null_;
set city_variables;
%do i= 1 %UNTIL (i = &amp;amp;count);  

call symput('name',CITY_NAME);
run;

From this point I want to create some datasets using Proc sql statements linking to an oracle table&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;create table &amp;amp;name as.....&lt;BR /&gt;from oracletable
%end;
%mend repeat;
%repeat&lt;BR /&gt;&lt;BR /&gt;-------&lt;BR /&gt;&lt;BR /&gt;I would like to be able to loop this process to create multiple datasets from the input dataset &lt;/CODE&gt;&lt;/PRE&gt;&lt;/DIV&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Tue, 02 May 2017 19:31:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Automate-the-Creation-of-Datasets-w-Macro-Program/m-p/355373#M83226</guid>
      <dc:creator>eparson</dc:creator>
      <dc:date>2017-05-02T19:31:12Z</dc:date>
    </item>
    <item>
      <title>Re: Automate the Creation of Datasets w/ Macro Program</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Automate-the-Creation-of-Datasets-w-Macro-Program/m-p/355377#M83227</link>
      <description>&lt;P&gt;What for would you do that?&lt;/P&gt;</description>
      <pubDate>Tue, 02 May 2017 19:39:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Automate-the-Creation-of-Datasets-w-Macro-Program/m-p/355377#M83227</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-05-02T19:39:05Z</dc:date>
    </item>
    <item>
      <title>Re: Automate the Creation of Datasets w/ Macro Program</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Automate-the-Creation-of-Datasets-w-Macro-Program/m-p/355378#M83228</link>
      <description>&lt;P&gt;Assuming you have made your connection to the (I assume Oracle database) then&lt;/P&gt;
&lt;PRE&gt;data _null_;
   set city_variables;
   Call execute ("proc sql;
create table "||city_name||" as.....
from oracletable; quit;");
run;&lt;/PRE&gt;
&lt;P&gt;where you actually provide the remaining code for the "...." part of proc sql.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Call execute can create code that is "stacked up" by the data step and executes after the data step runs. In effect creating as many calls to the sql portion are there are rows in the data set on the SET statement. This places the dataset variable value into the string submitted.&lt;/P&gt;</description>
      <pubDate>Tue, 02 May 2017 19:43:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Automate-the-Creation-of-Datasets-w-Macro-Program/m-p/355378#M83228</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-05-02T19:43:58Z</dc:date>
    </item>
    <item>
      <title>Re: Automate the Creation of Datasets w/ Macro Program</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Automate-the-Creation-of-Datasets-w-Macro-Program/m-p/355390#M83232</link>
      <description>&lt;P&gt;This is rarely a good way to process data and sends you do macro loop routes without a good reason. 90% of the time it's better to use some form of BY group processing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since you'll probably ignore this advice anyways, here's one posting that shows how to accomplish this:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.sas.com/content/sasdummy/2015/01/26/how-to-split-one-data-set-into-many/" target="_blank"&gt;http://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;
&lt;P&gt;This post goest into several variations with the same advice I mentioned - Best Practice is don't do this.&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;PS. Are you the same person who &amp;nbsp;asked this question on SO? The answers here will not be significantly different.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 May 2017 20:27:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Automate-the-Creation-of-Datasets-w-Macro-Program/m-p/355390#M83232</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-05-02T20:27:17Z</dc:date>
    </item>
    <item>
      <title>Re: Automate the Creation of Datasets w/ Macro Program</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Automate-the-Creation-of-Datasets-w-Macro-Program/m-p/355393#M83233</link>
      <description>&lt;P&gt;I'm not sure if this would be faster, but it might be:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data _null_;&lt;/P&gt;
&lt;P&gt;call execute('proc sql;');&lt;/P&gt;
&lt;P&gt;do until (done);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; set city_variables end=done;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; call execute('create table ............');&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;call execute('quit;');&lt;/P&gt;
&lt;P&gt;stop;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Tue, 02 May 2017 20:42:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Automate-the-Creation-of-Datasets-w-Macro-Program/m-p/355393#M83233</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-05-02T20:42:25Z</dc:date>
    </item>
    <item>
      <title>Re: Automate the Creation of Datasets w/ Macro Program</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Automate-the-Creation-of-Datasets-w-Macro-Program/m-p/355404#M83239</link>
      <description>&lt;P&gt;Because I have issues understanding %DO %TO as well as %DO %UNTIL and wanted to learn it more organically from being able to do it through a do loop from a real life example. &amp;nbsp;Of course there are more efficient ways which I will be implementing in the final program, but wanted to know how to do it this way. &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 May 2017 21:20:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Automate-the-Creation-of-Datasets-w-Macro-Program/m-p/355404#M83239</guid>
      <dc:creator>eparson</dc:creator>
      <dc:date>2017-05-02T21:20:36Z</dc:date>
    </item>
    <item>
      <title>Re: Automate the Creation of Datasets w/ Macro Program</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Automate-the-Creation-of-Datasets-w-Macro-Program/m-p/355447#M83244</link>
      <description>&lt;P&gt;If you really must get practice with a %DO loop, here's one way to approach your question:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro repeat;&lt;/P&gt;
&lt;P&gt;%local i;&lt;/P&gt;
&lt;P&gt;%do i=1 %to &amp;amp;count;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;data _null_;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;set city_variables (firsobs=&amp;amp;i obs=&amp;amp;i);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;call symputx('name', city_name);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;proc sql;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;create table &amp;amp;name as ......;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;quit;&lt;/P&gt;
&lt;P&gt;%end;&lt;/P&gt;
&lt;P&gt;%mend repeat;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%repeat&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that switching to CALL SYMPUTX will automatically strip out any leading or trailing blanks from the macro variable's value.&lt;/P&gt;</description>
      <pubDate>Wed, 03 May 2017 00:05:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Automate-the-Creation-of-Datasets-w-Macro-Program/m-p/355447#M83244</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-05-03T00:05:33Z</dc:date>
    </item>
    <item>
      <title>Re: Automate the Creation of Datasets w/ Macro Program</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Automate-the-Creation-of-Datasets-w-Macro-Program/m-p/355450#M83246</link>
      <description>&lt;P&gt;Check the SAS 9.4 Macro Appendix (search here for link) that has a bunch of really good examples for getting started with Macros.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 May 2017 00:11:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Automate-the-Creation-of-Datasets-w-Macro-Program/m-p/355450#M83246</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-05-03T00:11:24Z</dc:date>
    </item>
    <item>
      <title>Re: Automate the Creation of Datasets w/ Macro Program</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Automate-the-Creation-of-Datasets-w-Macro-Program/m-p/355626#M83289</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Because I have issues understanding %DO %TO as well as %DO %UNTIL and wanted to learn it more organically from being able to do it through a do loop from a real life example. &amp;nbsp;Of course there are more efficient ways which I will be implementing in the final program, but wanted to know how to do it this way. &lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 03 May 2017 14:40:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Automate-the-Creation-of-Datasets-w-Macro-Program/m-p/355626#M83289</guid>
      <dc:creator>eparson</dc:creator>
      <dc:date>2017-05-03T14:40:31Z</dc:date>
    </item>
    <item>
      <title>Re: Automate the Creation of Datasets w/ Macro Program</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Automate-the-Creation-of-Datasets-w-Macro-Program/m-p/355684#M83298</link>
      <description>&lt;P&gt;Thanks for adding this method. &amp;nbsp;I am still trying to wrap my head around this one and getting it to work. &amp;nbsp;I will continue to try to work this one, since I like the simplicity of the setup.&amp;nbsp;However, I am currently experiencing numerous syntax issues that I will need to work through. &amp;nbsp;Thanks again. &amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 03 May 2017 17:14:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Automate-the-Creation-of-Datasets-w-Macro-Program/m-p/355684#M83298</guid>
      <dc:creator>eparson</dc:creator>
      <dc:date>2017-05-03T17:14:51Z</dc:date>
    </item>
  </channel>
</rss>

