<?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 Counting vertically problem in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Counting-vertically-problem/m-p/117717#M293157</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Everyone,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a timeline dataset (simple 1,2,3,4..) and a dataset that record time a give person &lt;SPAN style="text-decoration: underline;"&gt;enter&lt;/SPAN&gt; and &lt;SPAN style="text-decoration: underline;"&gt;exit&lt;/SPAN&gt; a room.&lt;/P&gt;&lt;P&gt;I want to know at a given time, how many people are in the room.&lt;/P&gt;&lt;P&gt;I can do it with Proc sql but I am trying to count it vertically and still cannot get it.&lt;/P&gt;&lt;P&gt;My vertical code is as below and you can see, the method is quite clear.&lt;/P&gt;&lt;P&gt;For a give point in time, IF enter&amp;lt;time &amp;lt;exit then do; n=n+1;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you for your help.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;HHC&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data time;&lt;BR /&gt;input time;&lt;BR /&gt;datalines;&lt;BR /&gt;1&lt;BR /&gt;2&lt;BR /&gt;3&lt;BR /&gt;4&lt;BR /&gt;5&lt;BR /&gt;6&lt;BR /&gt;7&lt;BR /&gt;8&lt;/P&gt;&lt;P&gt;9&lt;/P&gt;&lt;P&gt;;&lt;BR /&gt;data have;&lt;BR /&gt;input enter exit;&lt;BR /&gt;datalines;&lt;BR /&gt;1 4&lt;BR /&gt;1 6&lt;BR /&gt;1 8&lt;BR /&gt;2 6&lt;BR /&gt;3 7&lt;BR /&gt;4 5&lt;BR /&gt;4 7&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;data Number;&lt;BR /&gt;set time;&lt;/P&gt;&lt;P&gt;n=0;&lt;BR /&gt;i+1;&lt;BR /&gt;set have;&lt;BR /&gt; if enter&amp;lt;time and time&amp;lt;exit then do;&lt;BR /&gt; n=n+1;&lt;BR /&gt; end;&lt;BR /&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 20 Oct 2013 03:01:05 GMT</pubDate>
    <dc:creator>hhchenfx</dc:creator>
    <dc:date>2013-10-20T03:01:05Z</dc:date>
    <item>
      <title>Counting vertically problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-vertically-problem/m-p/117717#M293157</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Everyone,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a timeline dataset (simple 1,2,3,4..) and a dataset that record time a give person &lt;SPAN style="text-decoration: underline;"&gt;enter&lt;/SPAN&gt; and &lt;SPAN style="text-decoration: underline;"&gt;exit&lt;/SPAN&gt; a room.&lt;/P&gt;&lt;P&gt;I want to know at a given time, how many people are in the room.&lt;/P&gt;&lt;P&gt;I can do it with Proc sql but I am trying to count it vertically and still cannot get it.&lt;/P&gt;&lt;P&gt;My vertical code is as below and you can see, the method is quite clear.&lt;/P&gt;&lt;P&gt;For a give point in time, IF enter&amp;lt;time &amp;lt;exit then do; n=n+1;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you for your help.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;HHC&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data time;&lt;BR /&gt;input time;&lt;BR /&gt;datalines;&lt;BR /&gt;1&lt;BR /&gt;2&lt;BR /&gt;3&lt;BR /&gt;4&lt;BR /&gt;5&lt;BR /&gt;6&lt;BR /&gt;7&lt;BR /&gt;8&lt;/P&gt;&lt;P&gt;9&lt;/P&gt;&lt;P&gt;;&lt;BR /&gt;data have;&lt;BR /&gt;input enter exit;&lt;BR /&gt;datalines;&lt;BR /&gt;1 4&lt;BR /&gt;1 6&lt;BR /&gt;1 8&lt;BR /&gt;2 6&lt;BR /&gt;3 7&lt;BR /&gt;4 5&lt;BR /&gt;4 7&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;data Number;&lt;BR /&gt;set time;&lt;/P&gt;&lt;P&gt;n=0;&lt;BR /&gt;i+1;&lt;BR /&gt;set have;&lt;BR /&gt; if enter&amp;lt;time and time&amp;lt;exit then do;&lt;BR /&gt; n=n+1;&lt;BR /&gt; end;&lt;BR /&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 20 Oct 2013 03:01:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-vertically-problem/m-p/117717#M293157</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2013-10-20T03:01:05Z</dc:date>
    </item>
    <item>
      <title>Re: Counting vertically problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-vertically-problem/m-p/117718#M293158</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Here's a somewhat inefficient solution:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;&lt;SPAN style="font-size: 10pt;"&gt;&lt;SPAN style="color: #011993;"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/SPAN&gt; have;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;&lt;SPAN style="font-size: 10pt;"&gt;&lt;SPAN style="color: #0433ff;"&gt;input&lt;/SPAN&gt; enter exit;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New'; color: #0433ff;"&gt;&lt;SPAN style="font-size: 10pt;"&gt;datalines&lt;SPAN style="color: #000000;"&gt;;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;&lt;SPAN style="font-size: 10pt;"&gt;1 4&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;&lt;SPAN style="font-size: 10pt;"&gt;1 6&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;&lt;SPAN style="font-size: 10pt;"&gt;1 8&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;&lt;SPAN style="font-size: 10pt;"&gt;2 6&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;&lt;SPAN style="font-size: 10pt;"&gt;3 7&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;&lt;SPAN style="font-size: 10pt;"&gt;4 5&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;&lt;SPAN style="font-size: 10pt;"&gt;4 7&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;&lt;SPAN style="font-size: 10pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New'; color: #011993;"&gt;&lt;SPAN style="font-size: 10pt;"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;SPAN style="color: #000000;"&gt;;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;&lt;SPAN style="font-size: 10pt;"&gt;&lt;SPAN style="color: #011993;"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/SPAN&gt; have2;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;&lt;SPAN style="font-size: 10pt;"&gt;&lt;SPAN style="color: #0433ff;"&gt;set&lt;/SPAN&gt; have;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;&lt;SPAN style="font-size: 10pt;"&gt;&lt;SPAN style="color: #0433ff;"&gt;do&lt;/SPAN&gt; person=enter &lt;SPAN style="color: #0433ff;"&gt;to&lt;/SPAN&gt; exit;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New'; color: #0433ff;"&gt;&lt;SPAN style="font-size: 10pt;"&gt;&lt;SPAN style="color: #000000;"&gt;&amp;nbsp; &lt;/SPAN&gt;output&lt;SPAN style="color: #000000;"&gt;;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New'; color: #0433ff;"&gt;&lt;SPAN style="font-size: 10pt;"&gt;end&lt;SPAN style="color: #000000;"&gt;;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New'; color: #011993;"&gt;&lt;SPAN style="font-size: 10pt;"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;SPAN style="color: #000000;"&gt;;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;&lt;SPAN style="font-size: 10pt;"&gt;&lt;SPAN style="color: #011993;"&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt;&lt;/SPAN&gt; &lt;SPAN style="color: #011993;"&gt;&lt;STRONG&gt;freq&lt;/STRONG&gt;&lt;/SPAN&gt; &lt;SPAN style="color: #0433ff;"&gt;data&lt;/SPAN&gt;=have2;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;&lt;SPAN style="font-size: 10pt;"&gt;&lt;SPAN style="color: #0433ff;"&gt;table&lt;/SPAN&gt; person/&lt;SPAN style="color: #0433ff;"&gt;out&lt;/SPAN&gt;=want1;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New'; color: #011993;"&gt;&lt;SPAN style="font-size: 10pt;"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;SPAN style="color: #000000;"&gt;;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 20 Oct 2013 03:40:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-vertically-problem/m-p/117718#M293158</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2013-10-20T03:40:16Z</dc:date>
    </item>
    <item>
      <title>Re: Counting vertically problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-vertically-problem/m-p/117719#M293159</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hash approach, &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if _n_=1 then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if 0 then set have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; declare hash h(dataset:'have', multidata:'y');&lt;/P&gt;&lt;P&gt;&amp;nbsp; h.definekey('enter');&lt;/P&gt;&lt;P&gt;&amp;nbsp; h.definedata(all:'y');&lt;/P&gt;&lt;P&gt;&amp;nbsp; h.definedone();&lt;/P&gt;&lt;P&gt; end;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; set time;&lt;/P&gt;&lt;P&gt; count=0; &lt;/P&gt;&lt;P&gt;exit=0;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; do i=time-1 by -1 while (i&amp;gt;0);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rc=h.find(key:i);&lt;/P&gt;&lt;P&gt;&amp;nbsp; do rc=0 by 0 while (rc=0);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if time&amp;lt;exit then count+1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; rc=h.find_next(key:i);&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; keep time count;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 20 Oct 2013 04:10:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-vertically-problem/m-p/117719#M293159</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2013-10-20T04:10:10Z</dc:date>
    </item>
    <item>
      <title>Re: Counting vertically problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-vertically-problem/m-p/117720#M293160</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The number of people in a room at a particular discrete points in time can easily be modeled as an array.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; person+1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; input enter exit @@;&lt;/P&gt;&lt;P&gt;cards;&lt;/P&gt;&lt;P&gt;1 4 1 6 1 8 2 6 3 7 4 5 4 7&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;data want ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; array cnt (10) _temporary_ ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if eof then do time=1 to dim(cnt);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; count=sum(0,cnt(time));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; keep time count;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set have end=eof;&lt;/P&gt;&lt;P&gt;&amp;nbsp; do time=enter to exit ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; cnt(time) = sum(1,cnt(time));&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;proc print;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 20 Oct 2013 16:11:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-vertically-problem/m-p/117720#M293160</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2013-10-20T16:11:44Z</dc:date>
    </item>
    <item>
      <title>Re: Counting vertically problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-vertically-problem/m-p/117721#M293161</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you all for different suggestion.&lt;/P&gt;&lt;P&gt;Since I try to practice the approach below (which I learn from Tom and other), I really appreciate if you could debug that code.&lt;/P&gt;&lt;P&gt;Have a nice weekend.&lt;/P&gt;&lt;P&gt;HHC&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data Number;&lt;BR /&gt;set time;&lt;/P&gt;&lt;P&gt;n=0;&lt;BR /&gt;i+1;&lt;BR /&gt;set have;&lt;BR /&gt; if enter&amp;lt;time and time&amp;lt;exit then do;&lt;BR /&gt; n=n+1;&lt;BR /&gt; end;&lt;BR /&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 20 Oct 2013 16:20:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-vertically-problem/m-p/117721#M293161</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2013-10-20T16:20:30Z</dc:date>
    </item>
    <item>
      <title>Re: Counting vertically problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-vertically-problem/m-p/117722#M293162</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think what you might be trying to do is loop over the HAVE dataset for every record in the TIME dataset.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;data number;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; set time;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; n=0;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; do i=1 to nobs ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; set have point=i nobs=nobs;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; n=n+ (enter &amp;lt;= time &amp;lt;= exit) ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; end;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; keep time n ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 20 Oct 2013 17:01:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-vertically-problem/m-p/117722#M293162</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2013-10-20T17:01:47Z</dc:date>
    </item>
    <item>
      <title>Re: Counting vertically problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-vertically-problem/m-p/117723#M293163</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you, Tom.&lt;/P&gt;&lt;P&gt;Yes, it is exactly what I want to do.&lt;/P&gt;&lt;P&gt;Still a lot to learn for me.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;HHC&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 20 Oct 2013 18:58:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-vertically-problem/m-p/117723#M293163</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2013-10-20T18:58:34Z</dc:date>
    </item>
  </channel>
</rss>

