<?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: Loop through dataset named with month_year in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Loop-through-dataset-named-with-month-year/m-p/749303#M235429</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;It might depend on what you are doing but instead of "looping through files" you could combine them, add a file identifier if needed and then use BY group processing for the stuff needed using that identifier.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Make that identifier something that sorts in proper order.&lt;/P&gt;
&lt;P&gt;Note that the INDSNAME option on a SET statement allows you to create a temporary variable with the name of the data set contributing the current record that you could parse as need.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If possible with these data sets, that would be even better than using a macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could combine all data sets into one via&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data all;
     set aa_: indsname=indsname;
     dsname=indsname;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and now you have everything you need to work with BY statements rather than a macro loop.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 21 Jun 2021 16:06:16 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2021-06-21T16:06:16Z</dc:date>
    <item>
      <title>Loop through dataset named with month_year</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-through-dataset-named-with-month-year/m-p/749283#M235421</link>
      <description>&lt;P&gt;Hi, I have datasets named with AA_MARCH_2019, AA_APRIL_2019, ..., AA_MAY_2021, and I want to create a loop function to execute the same process in each monthly file. How can I create a do loop to loop through these month_year files? Most of the SAS date format includes the date field, but here I just want the full month name and the year.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Mon, 21 Jun 2021 15:30:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-through-dataset-named-with-month-year/m-p/749283#M235421</guid>
      <dc:creator>newboy1218</dc:creator>
      <dc:date>2021-06-21T15:30:28Z</dc:date>
    </item>
    <item>
      <title>Re: Loop through dataset named with month_year</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-through-dataset-named-with-month-year/m-p/749285#M235422</link>
      <description>&lt;P&gt;Do not name datasets like this. Simply&amp;nbsp;&lt;STRONG&gt;DON'T.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Name them&lt;/P&gt;
&lt;PRE&gt;AA_201903
AA_201904&lt;/PRE&gt;
&lt;P&gt;and so on.&lt;/P&gt;
&lt;P&gt;Then you can use SAS dates and PUT with a YYMMN6. format. On top of that, the datasets will sort correctly on their own.&lt;/P&gt;
&lt;P&gt;Big hint: stupid data design forces stupid code.&lt;/P&gt;</description>
      <pubDate>Mon, 21 Jun 2021 15:36:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-through-dataset-named-with-month-year/m-p/749285#M235422</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-06-21T15:36:28Z</dc:date>
    </item>
    <item>
      <title>Re: Loop through dataset named with month_year</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-through-dataset-named-with-month-year/m-p/749286#M235423</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Yeah I understand. However, those files are created by our company data team. Now I just need to access them unfortunately. =(&lt;/P&gt;</description>
      <pubDate>Mon, 21 Jun 2021 15:39:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-through-dataset-named-with-month-year/m-p/749286#M235423</guid>
      <dc:creator>newboy1218</dc:creator>
      <dc:date>2021-06-21T15:39:19Z</dc:date>
    </item>
    <item>
      <title>Re: Loop through dataset named with month_year</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-through-dataset-named-with-month-year/m-p/749289#M235424</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro dothis(start,end);
    %let start=%sysevalf("&amp;amp;start"d);
    %let end=%sysevalf("&amp;amp;end"d);
    %let month=&amp;amp;start; 
    %let incr=0;
    %do %while(&amp;amp;month&amp;lt;=&amp;amp;end);
        %let filename=%sysfunc(putn(&amp;amp;month,monname3.))_%sysfunc(year(&amp;amp;month));
        /* Now that you have the filename, you can put code here that uses the file name */
        %let incr=%eval(&amp;amp;incr+1); %put &amp;amp;=incr;
        %let month=%sysfunc(intnx(month,&amp;amp;start,&amp;amp;incr,b)); 
    %end;
%mend;
%dothis(01MAR2019,01MAY2021)&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 21 Jun 2021 15:43:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-through-dataset-named-with-month-year/m-p/749289#M235424</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-06-21T15:43:26Z</dc:date>
    </item>
    <item>
      <title>Re: Loop through dataset named with month_year</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-through-dataset-named-with-month-year/m-p/749293#M235427</link>
      <description>&lt;P&gt;It might depend on what you are doing but instead of "looping through files" you could combine them, add a file identifier if needed and then use BY group processing for the stuff needed using that identifier.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Make that identifier something that sorts in proper order.&lt;/P&gt;
&lt;P&gt;Note that the INDSNAME option on a SET statement allows you to create a temporary variable with the name of the data set contributing the current record that you could parse as need.&lt;/P&gt;</description>
      <pubDate>Mon, 21 Jun 2021 15:49:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-through-dataset-named-with-month-year/m-p/749293#M235427</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-06-21T15:49:02Z</dc:date>
    </item>
    <item>
      <title>Re: Loop through dataset named with month_year</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-through-dataset-named-with-month-year/m-p/749303#M235429</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;It might depend on what you are doing but instead of "looping through files" you could combine them, add a file identifier if needed and then use BY group processing for the stuff needed using that identifier.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Make that identifier something that sorts in proper order.&lt;/P&gt;
&lt;P&gt;Note that the INDSNAME option on a SET statement allows you to create a temporary variable with the name of the data set contributing the current record that you could parse as need.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If possible with these data sets, that would be even better than using a macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could combine all data sets into one via&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data all;
     set aa_: indsname=indsname;
     dsname=indsname;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and now you have everything you need to work with BY statements rather than a macro loop.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 21 Jun 2021 16:06:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-through-dataset-named-with-month-year/m-p/749303#M235429</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-06-21T16:06:16Z</dc:date>
    </item>
    <item>
      <title>Re: Loop through dataset named with month_year</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-through-dataset-named-with-month-year/m-p/749307#M235431</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I see. So in the set statement, I would be combining all the datasets that has the name start with 'aa_' right? But what if I just want to combine a certain range of files? For example, in the library I have aa_january_2018 to aa_may_2021, and now I only need to use the files from aa_january_2019 to aa_may_2021?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And for the variable indsname, it would be the name of the aa_ file right?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Mon, 21 Jun 2021 16:11:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-through-dataset-named-with-month-year/m-p/749307#M235431</guid>
      <dc:creator>newboy1218</dc:creator>
      <dc:date>2021-06-21T16:11:33Z</dc:date>
    </item>
    <item>
      <title>Re: Loop through dataset named with month_year</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-through-dataset-named-with-month-year/m-p/749310#M235432</link>
      <description>SAS won't recognize the pattern in the dates if they're listed with the month name. If the pattern had the month numbers as suggested by Kurt earlier, then you could use a shortcut list to list the datasets. &lt;BR /&gt;&lt;BR /&gt;You can query sashelp.vtable to create a dynamically built list within your parameters.</description>
      <pubDate>Mon, 21 Jun 2021 16:28:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-through-dataset-named-with-month-year/m-p/749310#M235432</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-06-21T16:28:01Z</dc:date>
    </item>
    <item>
      <title>Re: Loop through dataset named with month_year</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-through-dataset-named-with-month-year/m-p/749365#M235463</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/211631"&gt;@newboy1218&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yeah I understand. However, those files are created by our company data team. Now I just need to access them unfortunately. =(&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I would have a discussion with the "data team" about the , let us say, suboptimal, naming pattern.&lt;/P&gt;
&lt;P&gt;Explain that a YYYYMM, ie 201912 1) sorts names properly at the operating system level as well as SAS library displays and 2) allows use of data set Lists in SAS. Depending on what process is currently naming them it may be easier to maintain as well as use.&lt;/P&gt;</description>
      <pubDate>Mon, 21 Jun 2021 19:29:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-through-dataset-named-with-month-year/m-p/749365#M235463</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-06-21T19:29:16Z</dc:date>
    </item>
    <item>
      <title>Re: Loop through dataset named with month_year</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-through-dataset-named-with-month-year/m-p/749385#M235474</link>
      <description>&lt;P&gt;Send this "data team" back to college, so they can finish Computer Science 101.&lt;/P&gt;
&lt;P&gt;It really hurts to see so-called professionals commit such egregious bloody-beginner mistakes.&lt;/P&gt;</description>
      <pubDate>Mon, 21 Jun 2021 21:31:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-through-dataset-named-with-month-year/m-p/749385#M235474</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-06-21T21:31:15Z</dc:date>
    </item>
    <item>
      <title>Re: Loop through dataset named with month_year</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-through-dataset-named-with-month-year/m-p/749392#M235481</link>
      <description>It's also a trivial exercise to rename them via alias or views so this isn't a hill I'd die on by any means.</description>
      <pubDate>Mon, 21 Jun 2021 22:41:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-through-dataset-named-with-month-year/m-p/749392#M235481</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-06-21T22:41:38Z</dc:date>
    </item>
  </channel>
</rss>

