<?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: Using a loop counter as part of a data step/variable name in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Using-a-loop-counter-as-part-of-a-data-step-variable-name/m-p/59306#M12845</link>
    <description>This is not possible:&lt;BR /&gt;
&lt;BR /&gt;
do i = 1 to 100;&lt;BR /&gt;
data month&amp;amp;i;&lt;BR /&gt;
set January;&lt;BR /&gt;
run;&lt;BR /&gt;
end;&lt;BR /&gt;
&lt;BR /&gt;
but, this is and actually works:&lt;BR /&gt;
&lt;BR /&gt;
%macro my_macro;&lt;BR /&gt;
&lt;BR /&gt;
%do i = 1 %to 100;&lt;BR /&gt;
data month&amp;amp;i;&lt;BR /&gt;
set January;&lt;BR /&gt;
run;&lt;BR /&gt;
%end;&lt;BR /&gt;
&lt;BR /&gt;
%men my_macro;&lt;BR /&gt;
%my_macro;&lt;BR /&gt;
&lt;BR /&gt;
datastep do...loop (the one without the %) is not permitted outside the datastep.&lt;BR /&gt;
&lt;BR /&gt;
macro do...loop (the one with the %) is permitted inside/outside the datastep but within a macro definition.&lt;BR /&gt;
&lt;BR /&gt;
Cheers from Portugal.&lt;BR /&gt;
&lt;BR /&gt;
Daniel Santos @ &lt;A href="http://www.cgd.pt" target="_blank"&gt;www.cgd.pt&lt;/A&gt;.</description>
    <pubDate>Tue, 28 Jul 2009 14:55:06 GMT</pubDate>
    <dc:creator>DanielSantos</dc:creator>
    <dc:date>2009-07-28T14:55:06Z</dc:date>
    <item>
      <title>Using a loop counter as part of a data step/variable name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-a-loop-counter-as-part-of-a-data-step-variable-name/m-p/59303#M12842</link>
      <description>Is it possible to use a counter as part of a data step or another sas variable name?&lt;BR /&gt;
&lt;BR /&gt;
For instance:"&lt;BR /&gt;
&lt;BR /&gt;
do i = 1 to 100;&lt;BR /&gt;
data month&amp;amp;i;&lt;BR /&gt;
set January;&lt;BR /&gt;
run;&lt;BR /&gt;
end;&lt;BR /&gt;
&lt;BR /&gt;
Is there anything to that effect?</description>
      <pubDate>Mon, 27 Jul 2009 21:32:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-a-loop-counter-as-part-of-a-data-step-variable-name/m-p/59303#M12842</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-07-27T21:32:19Z</dc:date>
    </item>
    <item>
      <title>Re: Using a loop counter as part of a data step/variable name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-a-loop-counter-as-part-of-a-data-step-variable-name/m-p/59304#M12843</link>
      <description>yes - you may use the _N_ variable which is the SAS counter I believe - increments by 1 each loop of the DATA step.</description>
      <pubDate>Mon, 27 Jul 2009 23:03:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-a-loop-counter-as-part-of-a-data-step-variable-name/m-p/59304#M12843</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-07-27T23:03:28Z</dc:date>
    </item>
    <item>
      <title>Re: Using a loop counter as part of a data step/variable name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-a-loop-counter-as-part-of-a-data-step-variable-name/m-p/59305#M12844</link>
      <description>You cannot mix SAS variables and SAS macro variables, as you have demonstrated.  Also, the SAS variable _N_ identifies the current observation number, in most circumstances during DATA step processing.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Tue, 28 Jul 2009 00:35:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-a-loop-counter-as-part-of-a-data-step-variable-name/m-p/59305#M12844</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-07-28T00:35:51Z</dc:date>
    </item>
    <item>
      <title>Re: Using a loop counter as part of a data step/variable name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-a-loop-counter-as-part-of-a-data-step-variable-name/m-p/59306#M12845</link>
      <description>This is not possible:&lt;BR /&gt;
&lt;BR /&gt;
do i = 1 to 100;&lt;BR /&gt;
data month&amp;amp;i;&lt;BR /&gt;
set January;&lt;BR /&gt;
run;&lt;BR /&gt;
end;&lt;BR /&gt;
&lt;BR /&gt;
but, this is and actually works:&lt;BR /&gt;
&lt;BR /&gt;
%macro my_macro;&lt;BR /&gt;
&lt;BR /&gt;
%do i = 1 %to 100;&lt;BR /&gt;
data month&amp;amp;i;&lt;BR /&gt;
set January;&lt;BR /&gt;
run;&lt;BR /&gt;
%end;&lt;BR /&gt;
&lt;BR /&gt;
%men my_macro;&lt;BR /&gt;
%my_macro;&lt;BR /&gt;
&lt;BR /&gt;
datastep do...loop (the one without the %) is not permitted outside the datastep.&lt;BR /&gt;
&lt;BR /&gt;
macro do...loop (the one with the %) is permitted inside/outside the datastep but within a macro definition.&lt;BR /&gt;
&lt;BR /&gt;
Cheers from Portugal.&lt;BR /&gt;
&lt;BR /&gt;
Daniel Santos @ &lt;A href="http://www.cgd.pt" target="_blank"&gt;www.cgd.pt&lt;/A&gt;.</description>
      <pubDate>Tue, 28 Jul 2009 14:55:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-a-loop-counter-as-part-of-a-data-step-variable-name/m-p/59306#M12845</guid>
      <dc:creator>DanielSantos</dc:creator>
      <dc:date>2009-07-28T14:55:06Z</dc:date>
    </item>
    <item>
      <title>Re: Using a loop counter as part of a data step/variable name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-a-loop-counter-as-part-of-a-data-step-variable-name/m-p/59307#M12846</link>
      <description>Suggest that the OP back up and reply to this post with detailed information about what is to be accomplished, for the most accurate input and thread discussion.  Providing an example of both INPUT and desired OUTPUT would be most helpful.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Tue, 28 Jul 2009 16:37:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-a-loop-counter-as-part-of-a-data-step-variable-name/m-p/59307#M12846</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-07-28T16:37:39Z</dc:date>
    </item>
    <item>
      <title>Re: Using a loop counter as part of a data step/variable name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-a-loop-counter-as-part-of-a-data-step-variable-name/m-p/59308#M12847</link>
      <description>Sure Scott,&lt;BR /&gt;
&lt;BR /&gt;
I am creating a data set for each month of the year. Instead of creating 12 data sets in a list, I want to use a loop and name the data sets Month1 - &lt;BR /&gt;
Month 12. &lt;BR /&gt;
&lt;BR /&gt;
Inside the data set I want to use a macro variable array that has date parameters. For example, Month_ST(1) = '01Jan2008'd....This way I can test to see if something happened during the proper time period for a particular month. &lt;BR /&gt;
&lt;BR /&gt;
I hope that makes things a bit clearer. Thanks for everyones help.</description>
      <pubDate>Tue, 28 Jul 2009 17:39:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-a-loop-counter-as-part-of-a-data-step-variable-name/m-p/59308#M12847</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-07-28T17:39:39Z</dc:date>
    </item>
    <item>
      <title>Re: Using a loop counter as part of a data step/variable name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-a-loop-counter-as-part-of-a-data-step-variable-name/m-p/59309#M12848</link>
      <description>Okay - you want to create MONTH1 through MONTH12 SAS files - separate with each file only having the specific MONTH value which would be derived from a SAS DATE variable?&lt;BR /&gt;
&lt;BR /&gt;
You can do this with SAS macro language as was mentioned in the previous post-reply.  The macro code will however also need to generate the SAS DATA step IF/THEN/OUTPUT statements  and the IF portion will need to use the MONTH function to test against some SAS DATE variable and use OUTPUT to the particular MONTHn-MONTHnn file.&lt;BR /&gt;
&lt;BR /&gt;
Or, manually code the DATA step with your 12 output files, a SET statement for your single input file, and then handcode the IF/THEN/OUTPUT/ELSE....  to use the MONTH(&lt;YOUR_DATE_VAR&gt;) function and direct the observation to the appropriate/desired output file.&lt;BR /&gt;
&lt;BR /&gt;
The SAS support website  &lt;A href="http://support.sas.com/" target="_blank"&gt;http://support.sas.com/&lt;/A&gt;   provides SAS-hosted product documentation and also supplemental technical and conference topic papers - a few of which I found and have pasted below for reference.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.&lt;BR /&gt;
&lt;BR /&gt;
SASâ Macro Programming for Beginners&lt;BR /&gt;
Susan J. Slaughter, Avocet Solutions, Davis, CA&lt;BR /&gt;
Lora D. Delwiche, Delwiche Consulting, Winters, CA&lt;BR /&gt;
&lt;A href="http://www2.sas.com/proceedings/sugi29/243-29.pdf" target="_blank"&gt;http://www2.sas.com/proceedings/sugi29/243-29.pdf&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
SAS® Macro Programming Tips and Techniques&lt;BR /&gt;
Kirk Paul Lafler, Software Intelligence Corporation, Spring Valley, California&lt;BR /&gt;
&lt;A href="http://support.sas.com/resources/papers/proceedings09/151-2009.pdf" target="_blank"&gt;http://support.sas.com/resources/papers/proceedings09/151-2009.pdf&lt;/A&gt;&lt;/YOUR_DATE_VAR&gt;</description>
      <pubDate>Tue, 28 Jul 2009 18:34:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-a-loop-counter-as-part-of-a-data-step-variable-name/m-p/59309#M12848</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-07-28T18:34:45Z</dc:date>
    </item>
  </channel>
</rss>

