<?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 Increase count for each run in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Increase-count-for-each-run/m-p/588331#M168128</link>
    <description>I have a situation where I need to increase the value by 1 to create a new variable(numeric) called 'count_execution' in one new dataset (want) if I execute any program from particular folder. Dataset 'want' is already created with 0 observation. So I want to insert value as 1 only for the first record in WANT dataset and for the subsequent records values should be dynamically inserted like 2, 3, 4, 5...  &lt;BR /&gt;&lt;BR /&gt;E.g.&lt;BR /&gt;&lt;BR /&gt;Count_execution&lt;BR /&gt;1 &lt;BR /&gt;2&lt;BR /&gt;3&lt;BR /&gt;</description>
    <pubDate>Thu, 12 Sep 2019 17:47:30 GMT</pubDate>
    <dc:creator>Babloo</dc:creator>
    <dc:date>2019-09-12T17:47:30Z</dc:date>
    <item>
      <title>Increase count for each run</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Increase-count-for-each-run/m-p/588331#M168128</link>
      <description>I have a situation where I need to increase the value by 1 to create a new variable(numeric) called 'count_execution' in one new dataset (want) if I execute any program from particular folder. Dataset 'want' is already created with 0 observation. So I want to insert value as 1 only for the first record in WANT dataset and for the subsequent records values should be dynamically inserted like 2, 3, 4, 5...  &lt;BR /&gt;&lt;BR /&gt;E.g.&lt;BR /&gt;&lt;BR /&gt;Count_execution&lt;BR /&gt;1 &lt;BR /&gt;2&lt;BR /&gt;3&lt;BR /&gt;</description>
      <pubDate>Thu, 12 Sep 2019 17:47:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Increase-count-for-each-run/m-p/588331#M168128</guid>
      <dc:creator>Babloo</dc:creator>
      <dc:date>2019-09-12T17:47:30Z</dc:date>
    </item>
    <item>
      <title>Re: Increase count for each run</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Increase-count-for-each-run/m-p/588332#M168129</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have end=eof;
output;
if eof
then do;
  count + 1;
  output;
end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 12 Sep 2019 17:52:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Increase-count-for-each-run/m-p/588332#M168129</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-09-12T17:52:23Z</dc:date>
    </item>
    <item>
      <title>Re: Increase count for each run</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Increase-count-for-each-run/m-p/588461#M168185</link>
      <description>&lt;P&gt;I ran the code below and I'm seeing the Output as&amp;nbsp;0 Observation &amp;nbsp;instead of 1 Observation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Desired Output is 1 for the run_id if there is no Observation in the HAVE dataset. If any Observation then I want to add the run_id by 1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input run_id;
datalines;
run;

data want;
set have nobs=nobservation nobs=n_obs;
if n_obs=0 then run_id=1;
else run_id+1;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Log:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;26         data have;
27         input run_id;
28         datalines;

NOTE: The data set WORK.HAVE has 0 observations and 1 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
      
29         run;

30         
31         data want;
32         set have nobs=nobservation nobs=n_obs;
33         if n_obs=0 then run_id=1;
34         else run_id+1;
35         run;

NOTE: There were 0 observations read from the data set WORK.HAVE.
NOTE: The data set WORK.WANT has 0 observations and 1 variables&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I tried with your apporach like below as well and it is also not working.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;26         data want;
27         set have end=eof;
28         output;
29         if eof
30         then do;
31           run_id+1;
32           output;
33         end;
34         run;

NOTE: There were 0 observations read from the data set WORK.HAVE.
NOTE: The data set WORK.WANT has 0 observations and 1 variables.&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 13 Sep 2019 10:11:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Increase-count-for-each-run/m-p/588461#M168185</guid>
      <dc:creator>Babloo</dc:creator>
      <dc:date>2019-09-13T10:11:45Z</dc:date>
    </item>
    <item>
      <title>Re: Increase count for each run</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Increase-count-for-each-run/m-p/588467#M168186</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/8409"&gt;@Babloo&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try this PROC SQL approach:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Assuming this already exists

data want;
stop;
run_id=.;
run;

*/

proc sql noprint;
select max(max(run_id)+1, 1) into :_newid
from want;

insert into want
set run_id=&amp;amp;_newid;
quit;

proc print data=want;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you run this code repeatedly, you'll see how dataset WANT is growing with RUN_ID=1, 2, 3, ...&lt;/P&gt;</description>
      <pubDate>Fri, 13 Sep 2019 10:39:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Increase-count-for-each-run/m-p/588467#M168186</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2019-09-13T10:39:41Z</dc:date>
    </item>
    <item>
      <title>Re: Increase count for each run</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Increase-count-for-each-run/m-p/588469#M168187</link>
      <description>Thanks. Curious to know about data step method as well.&lt;BR /&gt;</description>
      <pubDate>Fri, 13 Sep 2019 10:44:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Increase-count-for-each-run/m-p/588469#M168187</guid>
      <dc:creator>Babloo</dc:creator>
      <dc:date>2019-09-13T10:44:44Z</dc:date>
    </item>
    <item>
      <title>Re: Increase count for each run</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Increase-count-for-each-run/m-p/588470#M168188</link>
      <description>&lt;P&gt;Yes, we need to take care for the empty dataset:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
if _n_ = 1 and eof
then do;
  run_id = 1;
  output;
end;
set have end=eof;
output;
if eof
then do;
  run_id + 1;
  output;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 13 Sep 2019 10:51:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Increase-count-for-each-run/m-p/588470#M168188</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-09-13T10:51:50Z</dc:date>
    </item>
    <item>
      <title>Re: Increase count for each run</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Increase-count-for-each-run/m-p/588471#M168189</link>
      <description>&lt;P&gt;Okay, then try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
run_id=sum(n,1);
output;
stop;
set want nobs=n;
modify want;
run;

proc print data=want;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Again, run the above code repeatedly (starting with the empty WANT dataset) to see the effect.&lt;/P&gt;</description>
      <pubDate>Fri, 13 Sep 2019 10:58:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Increase-count-for-each-run/m-p/588471#M168189</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2019-09-13T10:58:02Z</dc:date>
    </item>
    <item>
      <title>Re: Increase count for each run</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Increase-count-for-each-run/m-p/588474#M168190</link>
      <description>&lt;P&gt;Despite executing the following code (only the below code and any step prior to it)&amp;nbsp;multiple times, I could see only the below NOTE. It's not adding any observation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;26         data want;
27         run_id=sum(n,1);
28         output;
29         stop;
30         set want nobs=n;
31         modify want;
32         run;

NOTE: The data set WORK.WANT has been updated.  There were 0 observations rewritten, 1 observations added and 0 observations 
      deleted.&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 13 Sep 2019 11:15:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Increase-count-for-each-run/m-p/588474#M168190</guid>
      <dc:creator>Babloo</dc:creator>
      <dc:date>2019-09-13T11:15:44Z</dc:date>
    </item>
    <item>
      <title>Re: Increase count for each run</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Increase-count-for-each-run/m-p/588480#M168193</link>
      <description>&lt;P&gt;Thanks, your code works well for 0 observation in the HAVE dataset. In case if I want to grow the run_id by 1 for each run, then how can we tweak the code.?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example, code below works well if I've Observation in HAVE and the code which you posted works well for 0 Observation. Now if I want to combine this behaviour&amp;nbsp;how can we do it?&amp;nbsp;I regret if I didn't meant this objective in my IP.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;27         data have;
28         input run_id;
29         datalines;

NOTE: The data set WORK.HAVE has 1 observations and 1 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
      
31         ;

32         run;
33         
34         
35         
36         
37         proc sql noprint;
38         	select max(max(run_id)+1, 1) into :_newid
39         		from want;
40         	insert into want
41         		set run_id=&amp;amp;_newid;
NOTE: 1 row was inserted into WORK.WANT.

42         quit;
NOTE: PROCEDURE SQL used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
      

43         
44         proc print data=want;
2                                                          The SAS System                     Friday, September 13, 2019 11:02:00 AM

45         run;

NOTE: There were 9 observations read from the data set WORK.WANT.&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 13 Sep 2019 11:37:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Increase-count-for-each-run/m-p/588480#M168193</guid>
      <dc:creator>Babloo</dc:creator>
      <dc:date>2019-09-13T11:37:10Z</dc:date>
    </item>
    <item>
      <title>Re: Increase count for each run</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Increase-count-for-each-run/m-p/588484#M168195</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/8409"&gt;@Babloo&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Despite executing the following code (only the below code and any step prior to it)&amp;nbsp;multiple times, I could see only the below NOTE. It's not adding any observation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;...
NOTE: The data set WORK.WANT has been updated.  There were 0 observations rewritten, &lt;FONT size="5" color="#FF0000"&gt;1 observations added&lt;/FONT&gt; and 0 observations 
      deleted.&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Why do you think it's "not adding any observation" when the log says "&lt;CODE class=" language-sas"&gt;1 observations added&lt;/CODE&gt;" and the PROC PRINT step (which you omitted from my code) confirms that?&lt;/P&gt;</description>
      <pubDate>Fri, 13 Sep 2019 11:47:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Increase-count-for-each-run/m-p/588484#M168195</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2019-09-13T11:47:29Z</dc:date>
    </item>
  </channel>
</rss>

