<?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: Looping for String Variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Looping-for-String-Variable/m-p/350706#M81550</link>
    <description>&lt;P&gt;I think Example 3 and 11 are what you're looking for, 3 is the solution to your question here and 11 is another option for your loop.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/SAS-9-4-Macro-Language-Reference-Has-a-New-Appendix/ta-p/291716" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/SAS-9-4-Macro-Language-Reference-Has-a-New-Appendix/ta-p/291716&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that you can use the MONNAME format to turn a date into the month name, ie January.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put %sysfunc(putn('01Jan2017'd, monname.));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The log will show&amp;nbsp;&lt;/P&gt;
&lt;P&gt;January.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 18 Apr 2017 05:02:13 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2017-04-18T05:02:13Z</dc:date>
    <item>
      <title>Looping for String Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Looping-for-String-Variable/m-p/350700#M81546</link>
      <description>&lt;P&gt;Hi SAS Expert!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a question on looping for string variables. First, I have multiple datasets and each of the file starts with the name&amp;nbsp; "TMIDRRPT_MONTHLY_" and then followed by month and year. For example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;TMIDRRPT_MONTHLY_January-2010.txt&lt;/P&gt;
&lt;P&gt;TMIDRRPT_MONTHLY_February-2010.txt&lt;/P&gt;
&lt;P&gt;... etc.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have created a macro to import multiple files in one go but it kept giving me the error code. If you can suggest a better way and/or spot my mistake, that will be greatly appreciated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Many thanks!&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;David&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let year=2010;

%macro imp(year);
%do i=2010 %to &amp;amp;year;
%do j='January','February','March';

proc import datafile="&amp;amp;input\TMIDRRPT_MONTHLY_&amp;amp;j-&amp;amp;i.txt" out=data.raw&amp;amp;j&amp;amp;i dbms=dlm replace;
   delimiter='|';
   getnames=yes;
run;

%end;
%end;
%mend;
%imp(&amp;amp;year);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Apr 2017 04:43:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Looping-for-String-Variable/m-p/350700#M81546</guid>
      <dc:creator>DavidLie</dc:creator>
      <dc:date>2017-04-18T04:43:50Z</dc:date>
    </item>
    <item>
      <title>Re: Looping for String Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Looping-for-String-Variable/m-p/350701#M81547</link>
      <description>&lt;P&gt;What's the error?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Post the log.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you search here you'll find some macros that can help with this issue. If all your files have the same format you can use a wildcard and import all at once.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Apr 2017 04:49:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Looping-for-String-Variable/m-p/350701#M81547</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-04-18T04:49:26Z</dc:date>
    </item>
    <item>
      <title>Re: Looping for String Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Looping-for-String-Variable/m-p/350704#M81548</link>
      <description>&lt;P&gt;Hi Reeza,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is the error message.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;508&amp;nbsp; %let year=2010;&lt;BR /&gt;509&lt;BR /&gt;510&amp;nbsp; %macro imp(year);&lt;BR /&gt;511&amp;nbsp; %do i=2010 %to &amp;amp;year;&lt;BR /&gt;512&amp;nbsp; %do j='January','February';&lt;BR /&gt;ERROR: Expected %TO not found in %DO statement.&lt;BR /&gt;ERROR: A dummy macro will be compiled.&lt;BR /&gt;513&lt;BR /&gt;514&amp;nbsp; proc import datafile="&amp;amp;input\TMIDRRPT_MONTHLY_&amp;amp;j-&amp;amp;i.txt" out=data.raw&amp;amp;j&amp;amp;i dbms=dlm&lt;BR /&gt;514! replace;&lt;BR /&gt;515&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; delimiter='|';&lt;BR /&gt;516&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; getnames=yes;&lt;BR /&gt;517&amp;nbsp; run;&lt;BR /&gt;518&lt;BR /&gt;519&amp;nbsp; %end;&lt;BR /&gt;520&amp;nbsp; %end;&lt;BR /&gt;521&amp;nbsp; %mend;&lt;BR /&gt;522&amp;nbsp; %imp(&amp;amp;year);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; -&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 180&lt;BR /&gt;WARNING: Apparent invocation of macro IMP not resolved.&lt;BR /&gt;&lt;BR /&gt;ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Apr 2017 04:56:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Looping-for-String-Variable/m-p/350704#M81548</guid>
      <dc:creator>DavidLie</dc:creator>
      <dc:date>2017-04-18T04:56:19Z</dc:date>
    </item>
    <item>
      <title>Re: Looping for String Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Looping-for-String-Variable/m-p/350706#M81550</link>
      <description>&lt;P&gt;I think Example 3 and 11 are what you're looking for, 3 is the solution to your question here and 11 is another option for your loop.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/SAS-9-4-Macro-Language-Reference-Has-a-New-Appendix/ta-p/291716" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/SAS-9-4-Macro-Language-Reference-Has-a-New-Appendix/ta-p/291716&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that you can use the MONNAME format to turn a date into the month name, ie January.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put %sysfunc(putn('01Jan2017'd, monname.));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The log will show&amp;nbsp;&lt;/P&gt;
&lt;P&gt;January.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Apr 2017 05:02:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Looping-for-String-Variable/m-p/350706#M81550</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-04-18T05:02:13Z</dc:date>
    </item>
    <item>
      <title>Re: Looping for String Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Looping-for-String-Variable/m-p/350707#M81551</link>
      <description>&lt;P&gt;As you go through the examples that &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt; pointed out you will discover that not all DATA step knowledge is transferrable to the macro language.&amp;nbsp; For instance as you already found, macro %DO loops cannot iterate across character strings with multiple loop specifications - as can DATA&amp;nbsp; step loops.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also when appending text to a macro variable the dot or period is used to identify the end of the macro variable name. when appending a dot, a double dot is needed. in part your file name becomes &amp;amp;i-&amp;amp;j..txt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Apr 2017 05:27:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Looping-for-String-Variable/m-p/350707#M81551</guid>
      <dc:creator>ArtC</dc:creator>
      <dc:date>2017-04-18T05:27:20Z</dc:date>
    </item>
    <item>
      <title>Re: Looping for String Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Looping-for-String-Variable/m-p/350762#M81572</link>
      <description>&lt;P&gt;Here's some detail about the original situation causing the problem:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.sas.com/content/sastraining/2015/01/30/sas-authors-tip-getting-the-macro-language-to-perform-a-do-loop-over-a-list-of-values/" target="_blank"&gt;http://blogs.sas.com/content/sastraining/2015/01/30/sas-authors-tip-getting-the-macro-language-to-perform-a-do-loop-over-a-list-of-values/&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As Art mentioned, you will need to add the dot as well.&lt;/P&gt;</description>
      <pubDate>Tue, 18 Apr 2017 09:52:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Looping-for-String-Variable/m-p/350762#M81572</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-04-18T09:52:58Z</dc:date>
    </item>
  </channel>
</rss>

