<?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: Auto increment and save a field in SAS in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Auto-increment-and-save-a-field-in-SAS/m-p/123465#M25341</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for your help Astounding.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I haven't decided if this will be a macro or DATA step. all I want to produce is &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;H,&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;ddmmyyyy,runnumber. Then I have to add this line to the top of the other dataset I produced with a simple PROC SQL, then a trailer line at the end (again simple one line dataset created with PROC SQL).&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;I just want to know how to create a runnumber variable which increments itself each time I run this in SAS EG, so I can add that to the header line.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;If I'm not clear enough, please let me know; I'm new to this area.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;Thanks again.&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 28 Aug 2013 21:40:44 GMT</pubDate>
    <dc:creator>tuncay</dc:creator>
    <dc:date>2013-08-28T21:40:44Z</dc:date>
    <item>
      <title>Auto increment and save a field in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Auto-increment-and-save-a-field-in-SAS/m-p/123462#M25338</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi everyone,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a question that I couldn't find the solution after much looking around.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am trying to convert a VBA macro (everything done, except this part) which runs sqlplusw to extract data, copy into excel worksheet and saves it. In this macro the header line has a run number, and this run number is incremented one each time we run it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is there a function in SAS that I can start from a definite number and increment the run number by itself each time I run it?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'd like to get a line something like below:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;H,ddmmyyy,runnumber&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Sorry if I'm not that clear, I'm a beginner in SAS.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Fatih&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 28 Aug 2013 04:16:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Auto-increment-and-save-a-field-in-SAS/m-p/123462#M25338</guid>
      <dc:creator>tuncay</dc:creator>
      <dc:date>2013-08-28T04:16:14Z</dc:date>
    </item>
    <item>
      <title>Re: Auto increment and save a field in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Auto-increment-and-save-a-field-in-SAS/m-p/123463#M25339</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Fatih,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Well, I need to imagine a bit how you are going to be using this.&amp;nbsp; Is it going to be in a DATA step or in a macro, for example?&amp;nbsp; As long as your run numbers are integers, both the DATA step and macro language would support any of these loops:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;do n=1 to number_of_files;&lt;/P&gt;&lt;P&gt;&amp;nbsp; new_runnumber = runnumber * n;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;runnumber = runnumber + runnumber;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;runnumber = runnumber + 1;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You might be looking for this combination:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%global new_runnumber;&lt;/P&gt;&lt;P&gt;%let new_runnumber = %eval(&amp;amp;new_runnumber +&amp;amp;runnumber);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You would have to provide some more detail about your SAS application if you need help picking out the right approach.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Good luck.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 28 Aug 2013 15:13:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Auto-increment-and-save-a-field-in-SAS/m-p/123463#M25339</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2013-08-28T15:13:34Z</dc:date>
    </item>
    <item>
      <title>Re: Auto increment and save a field in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Auto-increment-and-save-a-field-in-SAS/m-p/123464#M25340</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Is this to keep track of runs across SAS sessions or within a single session?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If there doesn't need to be any persistence across sessions the easiest would be to have a piece of code that only runs once, say in a SAS Autoexec.sas file, like :&lt;/P&gt;&lt;P&gt;%let RunNumber=0;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then at the top of the code you need:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let RunNumber = %eval(&amp;amp;RunNumber +1);&lt;BR /&gt;%put &amp;amp;RunNumber; /* to see output in log while testing*/&lt;/P&gt;&lt;P&gt;%let Header= H,%sysfunc(putn("&amp;amp;sysdate"d,ddmmyyn8.)),&amp;amp;RunNumber;&lt;/P&gt;&lt;P&gt;%put &amp;amp;Header; /* to see output while testing*/&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The Header would be referenced if file names similar to&lt;/P&gt;&lt;P&gt;filename outfile "C:\thisfolder\&amp;amp;header..txt";&amp;nbsp; /*note the first . is to concatenate with the .txt part of file name*/&lt;/P&gt;&lt;P&gt;or in atitle statement&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;title3 "Run: &amp;amp;Header";&lt;/P&gt;&lt;P&gt;Or "&amp;amp;Header" most places where the text is needed&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If it needs to persist across sessions things get a tad trickier.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 28 Aug 2013 15:21:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Auto-increment-and-save-a-field-in-SAS/m-p/123464#M25340</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2013-08-28T15:21:22Z</dc:date>
    </item>
    <item>
      <title>Re: Auto increment and save a field in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Auto-increment-and-save-a-field-in-SAS/m-p/123465#M25341</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for your help Astounding.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I haven't decided if this will be a macro or DATA step. all I want to produce is &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;H,&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;ddmmyyyy,runnumber. Then I have to add this line to the top of the other dataset I produced with a simple PROC SQL, then a trailer line at the end (again simple one line dataset created with PROC SQL).&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;I just want to know how to create a runnumber variable which increments itself each time I run this in SAS EG, so I can add that to the header line.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;If I'm not clear enough, please let me know; I'm new to this area.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;Thanks again.&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 28 Aug 2013 21:40:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Auto-increment-and-save-a-field-in-SAS/m-p/123465#M25341</guid>
      <dc:creator>tuncay</dc:creator>
      <dc:date>2013-08-28T21:40:44Z</dc:date>
    </item>
    <item>
      <title>Re: Auto increment and save a field in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Auto-increment-and-save-a-field-in-SAS/m-p/123466#M25342</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi ballardw,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is to keep track of runs across sessions. If I cannot find a solution, we will just manually change the number each time we run this code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It's interesting that such an easy thing in VBA (which I have very very limited knowledge of; but looking at previous reports I can decipher it) is too hard to accomplish in a powerful program like SAS.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 28 Aug 2013 21:46:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Auto-increment-and-save-a-field-in-SAS/m-p/123466#M25342</guid>
      <dc:creator>tuncay</dc:creator>
      <dc:date>2013-08-28T21:46:27Z</dc:date>
    </item>
  </channel>
</rss>

