<?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: What is the value of cnt in the statement? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/What-is-the-value-of-cnt-in-the-statement/m-p/828404#M327244</link>
    <description>It seems that variable cnt is a vestige. It is a counter that was not fully enacted. To make it work, for example, by counting the number of outputted observations with datemount &amp;gt; “202221”, you would need to put it in a do-loop like instead of “then output” write &lt;BR /&gt;…then do;&lt;BR /&gt;Output;&lt;BR /&gt;Cnt + 1;&lt;BR /&gt;End;&lt;BR /&gt;The top condition would make more sense with cnt = 0, or the counter will show one more observation.</description>
    <pubDate>Fri, 12 Aug 2022 03:10:12 GMT</pubDate>
    <dc:creator>pink_poodle</dc:creator>
    <dc:date>2022-08-12T03:10:12Z</dc:date>
    <item>
      <title>What is the value of cnt in the statement?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-is-the-value-of-cnt-in-the-statement/m-p/828388#M327235</link>
      <description>&lt;P&gt;Hello team,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have inherited a code that I run on a monthly basis.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data mydata;&lt;/P&gt;
&lt;P&gt;set mydata1 where (keep this that datatime where=(datepart(datetime) &amp;gt;= "01012021"&lt;/P&gt;
&lt;P&gt;mydata2 (keep=datetime fileNum);&lt;/P&gt;
&lt;P&gt;cnt = 1;&lt;/P&gt;
&lt;P&gt;date1 = datepart(datetime);&lt;/P&gt;
&lt;P&gt;datemount = put(date1, yymmn6.);&lt;/P&gt;
&lt;P&gt;if datemount &amp;gt; "202201" then output;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc summary nway missing data =mydata;&lt;/P&gt;
&lt;P&gt;var cnt;&lt;/P&gt;
&lt;P&gt;........&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;on the first statement? Does cnt becomes 1 when the first time SAS reads the first record and then it becomes 2 on the second row since SAS reads sequentially.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What is the value of cnt on the second statement? Is it incremented?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can anyone please kindly explain it to me?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;BlueBerry&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>Thu, 11 Aug 2022 23:22:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-is-the-value-of-cnt-in-the-statement/m-p/828388#M327235</guid>
      <dc:creator>GN0001</dc:creator>
      <dc:date>2022-08-11T23:22:46Z</dc:date>
    </item>
    <item>
      <title>Re: What is the value of cnt in the statement?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-is-the-value-of-cnt-in-the-statement/m-p/828398#M327240</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;What is the value of cnt in the statement?&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Since the code sets CNT to one on every observations that means the variable cnt will have one on every observation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But another way to interpret that questions is&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;What value does the CNT variable add to this code&amp;nbsp;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;It kind of depends on what you are using PROC SUMMARY to do in that last step.&amp;nbsp; But it does not look like it is adding any value.&amp;nbsp; Let's do a simple test using SASHELP.CLASS.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=sashelp.class;
 output out=want;
run;

proc print data=want;
run;

data class;
 set sashelp.class;
 cnt=1;
run;

proc summary data=class;
  var cnt;
  output out=want;
run;

proc print data=want;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The only useful statistic is the count of observations that the _FREQ_ variable already provided.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_0-1660270910566.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/74383i2FE7C275A93F1C3F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Tom_0-1660270910566.png" alt="Tom_0-1660270910566.png" /&gt;&lt;/span&gt;&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>Fri, 12 Aug 2022 02:22:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-is-the-value-of-cnt-in-the-statement/m-p/828398#M327240</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-08-12T02:22:46Z</dc:date>
    </item>
    <item>
      <title>Re: What is the value of cnt in the statement?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-is-the-value-of-cnt-in-the-statement/m-p/828404#M327244</link>
      <description>It seems that variable cnt is a vestige. It is a counter that was not fully enacted. To make it work, for example, by counting the number of outputted observations with datemount &amp;gt; “202221”, you would need to put it in a do-loop like instead of “then output” write &lt;BR /&gt;…then do;&lt;BR /&gt;Output;&lt;BR /&gt;Cnt + 1;&lt;BR /&gt;End;&lt;BR /&gt;The top condition would make more sense with cnt = 0, or the counter will show one more observation.</description>
      <pubDate>Fri, 12 Aug 2022 03:10:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-is-the-value-of-cnt-in-the-statement/m-p/828404#M327244</guid>
      <dc:creator>pink_poodle</dc:creator>
      <dc:date>2022-08-12T03:10:12Z</dc:date>
    </item>
    <item>
      <title>Re: What is the value of cnt in the statement?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-is-the-value-of-cnt-in-the-statement/m-p/828409#M327245</link>
      <description>&lt;P&gt;Your code won't run anyway because of syntax errors:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;set mydata1 where (keep this that datatime where=(datepart(datetime) &amp;gt;= "01012021"
mydata2 (keep=datetime fileNum);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You have four opening, but only two closing brackets.&lt;/P&gt;
&lt;P&gt;Do you really want to include a dataset named "WHERE"?&lt;/P&gt;
&lt;P&gt;The result of DATEPART is a number, so comparing it to a string won't work.&lt;/P&gt;</description>
      <pubDate>Fri, 12 Aug 2022 05:30:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-is-the-value-of-cnt-in-the-statement/m-p/828409#M327245</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-08-12T05:30:56Z</dc:date>
    </item>
  </channel>
</rss>

