<?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: Trying to compare records in a data step in SAS Data Science</title>
    <link>https://communities.sas.com/t5/SAS-Data-Science/Trying-to-compare-records-in-a-data-step/m-p/229304#M3228</link>
    <description>&lt;P&gt;So:&lt;/P&gt;
&lt;PRE&gt;proc sql;
  create table WANT as
  select   distinct COLOR,
              count(COLOR) as NUM
  from     HAVE
  group by COLOR;
quit;&lt;/PRE&gt;</description>
    <pubDate>Fri, 09 Oct 2015 14:58:47 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2015-10-09T14:58:47Z</dc:date>
    <item>
      <title>Trying to compare records in a data step</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Trying-to-compare-records-in-a-data-step/m-p/229288#M3223</link>
      <description>&lt;P&gt;I have a table and I am trying to compare the the colors. Basically in the datastep... I want the primary color blue to count.. if the primary color blue isn't there I want to count the green... if no green then don't count. I am trying to understand how to write this so the observation looks at the next one&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data new; set color_table;&lt;/P&gt;&lt;P&gt;if first.person and color='green' then;&lt;/P&gt;&lt;P&gt;count;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Person&lt;/TD&gt;&lt;TD&gt;Color&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Paul&lt;/TD&gt;&lt;TD&gt;green&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Paul&lt;/TD&gt;&lt;TD&gt;blue&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Paul&lt;/TD&gt;&lt;TD&gt;red&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Paul&lt;/TD&gt;&lt;TD&gt;green&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Paul&lt;/TD&gt;&lt;TD&gt;blue&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;end result&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Person&lt;/TD&gt;&lt;TD&gt;Color&lt;/TD&gt;&lt;TD&gt;Count&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Paul&lt;/TD&gt;&lt;TD&gt;blue&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Paul&lt;/TD&gt;&lt;TD&gt;green&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Paul&lt;/TD&gt;&lt;TD&gt;red&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Paul&lt;/TD&gt;&lt;TD&gt;green&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Paul&lt;/TD&gt;&lt;TD&gt;blue&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Oct 2015 13:56:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Trying-to-compare-records-in-a-data-step/m-p/229288#M3223</guid>
      <dc:creator>paul2877</dc:creator>
      <dc:date>2015-10-09T13:56:39Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to compare records in a data step</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Trying-to-compare-records-in-a-data-step/m-p/229291#M3225</link>
      <description>&lt;P&gt;Trying to understand if there was a volume column there as well .. to sum up that column?&lt;/P&gt;</description>
      <pubDate>Fri, 09 Oct 2015 14:04:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Trying-to-compare-records-in-a-data-step/m-p/229291#M3225</guid>
      <dc:creator>paul2877</dc:creator>
      <dc:date>2015-10-09T14:04:02Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to compare records in a data step</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Trying-to-compare-records-in-a-data-step/m-p/229298#M3226</link>
      <description>&lt;P&gt;Sorry, I am really not following the logic. &amp;nbsp;What do you mean by if blue is not there then count green? &amp;nbsp;Both colors are in the data? &amp;nbsp;If you mean sequentially, then you would need to attribute a distinct sequential order to the data.&lt;/P&gt;</description>
      <pubDate>Fri, 09 Oct 2015 14:28:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Trying-to-compare-records-in-a-data-step/m-p/229298#M3226</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2015-10-09T14:28:32Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to compare records in a data step</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Trying-to-compare-records-in-a-data-step/m-p/229300#M3227</link>
      <description>&lt;P&gt;what I am trying &amp;nbsp;to do is count one color or the other... For Paul.. I want to add 1 if the color is blue.. but if the next record is green.. don't count green..&lt;/P&gt;</description>
      <pubDate>Fri, 09 Oct 2015 14:37:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Trying-to-compare-records-in-a-data-step/m-p/229300#M3227</guid>
      <dc:creator>paul2877</dc:creator>
      <dc:date>2015-10-09T14:37:03Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to compare records in a data step</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Trying-to-compare-records-in-a-data-step/m-p/229304#M3228</link>
      <description>&lt;P&gt;So:&lt;/P&gt;
&lt;PRE&gt;proc sql;
  create table WANT as
  select   distinct COLOR,
              count(COLOR) as NUM
  from     HAVE
  group by COLOR;
quit;&lt;/PRE&gt;</description>
      <pubDate>Fri, 09 Oct 2015 14:58:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Trying-to-compare-records-in-a-data-step/m-p/229304#M3228</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2015-10-09T14:58:47Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to compare records in a data step</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Trying-to-compare-records-in-a-data-step/m-p/229306#M3229</link>
      <description>This will give me a count by group.. however I only want to count green if blue isn't there.</description>
      <pubDate>Fri, 09 Oct 2015 15:01:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Trying-to-compare-records-in-a-data-step/m-p/229306#M3229</guid>
      <dc:creator>paul2877</dc:creator>
      <dc:date>2015-10-09T15:01:02Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to compare records in a data step</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Trying-to-compare-records-in-a-data-step/m-p/229309#M3230</link>
      <description>&lt;P&gt;Which then goes back to my previous question as in your test data, blue is clearly there?&lt;/P&gt;
&lt;TABLE&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;Person&lt;/TD&gt;
&lt;TD&gt;Color&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Paul&lt;/TD&gt;
&lt;TD&gt;green&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Paul&lt;/TD&gt;
&lt;TD&gt;blue&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Paul&lt;/TD&gt;
&lt;TD&gt;red&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Paul&lt;/TD&gt;
&lt;TD&gt;green&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Paul&lt;/TD&gt;
&lt;TD&gt;blue&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Second and last row.&lt;/P&gt;</description>
      <pubDate>Fri, 09 Oct 2015 15:04:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Trying-to-compare-records-in-a-data-step/m-p/229309#M3230</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2015-10-09T15:04:04Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to compare records in a data step</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Trying-to-compare-records-in-a-data-step/m-p/229311#M3231</link>
      <description>Yep.. I know .. but I have a large data set.. and it won't always be the case. I need to look at each observation to see what the color is.. then if the first oberservation is blue then =1 .. if we go to the second oberservation it's green, how do I tell it to look at the previous observation to know that it was blue.&lt;BR /&gt;</description>
      <pubDate>Fri, 09 Oct 2015 15:09:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Trying-to-compare-records-in-a-data-step/m-p/229311#M3231</guid>
      <dc:creator>paul2877</dc:creator>
      <dc:date>2015-10-09T15:09:14Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to compare records in a data step</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Trying-to-compare-records-in-a-data-step/m-p/229316#M3232</link>
      <description>&lt;P&gt;But what does observation order have to do with anything? &amp;nbsp;If there is a record in the data for that particular group of blue, then there is a records in that particular group = blue, if its the first obs or the 5th doesn't matter. &amp;nbsp;A mere matter of sorting the data appropriately will put the blue in the correct order, so I sort your dataset:&lt;/P&gt;
&lt;P&gt;Paul &amp;nbsp; Blue&lt;/P&gt;
&lt;P&gt;Paul &amp;nbsp; Blue&lt;/P&gt;
&lt;P&gt;Paul &amp;nbsp; Green&lt;/P&gt;
&lt;P&gt;Paul &amp;nbsp; Green&lt;/P&gt;
&lt;P&gt;Paul &amp;nbsp; Red&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are Blue records?&lt;/P&gt;</description>
      <pubDate>Fri, 09 Oct 2015 15:24:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Trying-to-compare-records-in-a-data-step/m-p/229316#M3232</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2015-10-09T15:24:26Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to compare records in a data step</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Trying-to-compare-records-in-a-data-step/m-p/229326#M3233</link>
      <description>This is how I want the output to look at the previous obs to see if blue was in the list.. if it's not.. I want to have green have a count.. here is 2 scenarios&lt;BR /&gt;Person Color Count&lt;BR /&gt;Paul blue 1&lt;BR /&gt;Paul blue 1&lt;BR /&gt;Paul green 0&lt;BR /&gt;Paul green 0&lt;BR /&gt;Paul red 0&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Person Color Count&lt;BR /&gt;Paul green 1&lt;BR /&gt;Paul green 1&lt;BR /&gt;Paul red 0&lt;BR /&gt;</description>
      <pubDate>Fri, 09 Oct 2015 16:03:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Trying-to-compare-records-in-a-data-step/m-p/229326#M3233</guid>
      <dc:creator>paul2877</dc:creator>
      <dc:date>2015-10-09T16:03:50Z</dc:date>
    </item>
  </channel>
</rss>

