<?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: How to conditionally check the difference between rows? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-conditionally-check-the-difference-between-rows/m-p/351942#M81999</link>
    <description>Are there always two white followed by two black with the same two states repeating the same order? Or do you have some of these where there are 3 or more states involved? Any with only one state?</description>
    <pubDate>Thu, 20 Apr 2017 22:46:15 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2017-04-20T22:46:15Z</dc:date>
    <item>
      <title>How to conditionally check the difference between rows?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-conditionally-check-the-difference-between-rows/m-p/351939#M81996</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Could you please let me know if there is any way to conditionally check the difference between rows?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For eg:&lt;/P&gt;
&lt;P&gt;I have the below dataset(Have), where I need to calculate the shot differences between WHITE and BLACK(race) in corresponding states. i.e calculate the difference between WHITE and BLACK in California then Arizona..etc(dataset NEED below):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Dataset -Have&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;Race &amp;nbsp;Shot_rcvd &amp;nbsp;Area&lt;/P&gt;
&lt;P&gt;WHITE 10 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; CALIFORNIA&lt;/P&gt;
&lt;P&gt;WHITE 20 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ARIZONA&lt;/P&gt;
&lt;P&gt;BLACK 21 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;CALIFORNIA&lt;/P&gt;
&lt;P&gt;BALCK 5 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;ARIZONA&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Dataset Need&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;Race &amp;nbsp;Shot_rcvd &amp;nbsp;Area &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Diff_in_shots&lt;/P&gt;
&lt;P&gt;WHITE 10 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; CALIFORNIA &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -11&lt;/P&gt;
&lt;P&gt;WHITE 20 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ARIZONA &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 15&lt;/P&gt;
&lt;P&gt;BLACK 21 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;CALIFORNIA &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 11&lt;/P&gt;
&lt;P&gt;BALCK 5 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;ARIZONA &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -15&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please let me know your suggestions.&lt;/P&gt;</description>
      <pubDate>Thu, 20 Apr 2017 22:35:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-conditionally-check-the-difference-between-rows/m-p/351939#M81996</guid>
      <dc:creator>renjithr</dc:creator>
      <dc:date>2017-04-20T22:35:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to conditionally check the difference between rows?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-conditionally-check-the-difference-between-rows/m-p/351942#M81999</link>
      <description>Are there always two white followed by two black with the same two states repeating the same order? Or do you have some of these where there are 3 or more states involved? Any with only one state?</description>
      <pubDate>Thu, 20 Apr 2017 22:46:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-conditionally-check-the-difference-between-rows/m-p/351942#M81999</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-04-20T22:46:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to conditionally check the difference between rows?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-conditionally-check-the-difference-between-rows/m-p/351943#M82000</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;No, it is not going to be the same..there are more states and the numbers of white and black are different too.For some states there will be two black and one white or one black and 4 white or 2 black and 1 white..etc.&lt;/P&gt;</description>
      <pubDate>Thu, 20 Apr 2017 22:51:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-conditionally-check-the-difference-between-rows/m-p/351943#M82000</guid>
      <dc:creator>renjithr</dc:creator>
      <dc:date>2017-04-20T22:51:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to conditionally check the difference between rows?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-conditionally-check-the-difference-between-rows/m-p/351945#M82001</link>
      <description>&lt;P&gt;Your example data should include at least one case of each of the types/ combinations of things going on.&lt;/P&gt;
&lt;P&gt;If there are dates of events to consider that may be a good idea to include.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If this data is the result of summarizing some data it may be better to post some examples from that data as sometimes raw data makes more sense than summarized for certain forms of manipulation.&lt;/P&gt;</description>
      <pubDate>Thu, 20 Apr 2017 23:02:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-conditionally-check-the-difference-between-rows/m-p/351945#M82001</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-04-20T23:02:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to conditionally check the difference between rows?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-conditionally-check-the-difference-between-rows/m-p/351947#M82003</link>
      <description>&lt;P&gt;Sure, here is a snapshot of the real data:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE width="292"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="64"&gt;RACE&lt;/TD&gt;
&lt;TD width="64"&gt;STATE&lt;/TD&gt;
&lt;TD width="100"&gt;vaccinated_cnt&lt;/TD&gt;
&lt;TD width="64"&gt;DATE&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;WHITE&lt;/TD&gt;
&lt;TD&gt;CALIFORNIA&lt;/TD&gt;
&lt;TD&gt;2&lt;/TD&gt;
&lt;TD&gt;Sep2016&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;WHITE&lt;/TD&gt;
&lt;TD&gt;ARIZONA&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;Sep2016&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;WHITE&lt;/TD&gt;
&lt;TD&gt;TEXAS&lt;/TD&gt;
&lt;TD&gt;50&lt;/TD&gt;
&lt;TD&gt;Oct2016&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;BLACK&lt;/TD&gt;
&lt;TD&gt;CALIFORNIA&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;Sep2016&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;BLACK&lt;/TD&gt;
&lt;TD&gt;ARIZONA&lt;/TD&gt;
&lt;TD&gt;5&lt;/TD&gt;
&lt;TD&gt;Sep2016&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;BLACK&lt;/TD&gt;
&lt;TD&gt;TEXAS&lt;/TD&gt;
&lt;TD&gt;10&lt;/TD&gt;
&lt;TD&gt;Oct2016&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
      <pubDate>Thu, 20 Apr 2017 23:12:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-conditionally-check-the-difference-between-rows/m-p/351947#M82003</guid>
      <dc:creator>renjithr</dc:creator>
      <dc:date>2017-04-20T23:12:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to conditionally check the difference between rows?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-conditionally-check-the-difference-between-rows/m-p/351958#M82007</link>
      <description>&lt;P&gt;Maybe I'm misunderstanding but a direct comparison doesn't make sense. Wouldn't you need rates to compare? Raw numbers don't provide the correct context.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Apr 2017 00:08:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-conditionally-check-the-difference-between-rows/m-p/351958#M82007</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-04-21T00:08:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to conditionally check the difference between rows?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-conditionally-check-the-difference-between-rows/m-p/351971#M82009</link>
      <description>&lt;P&gt;Trying to figure out the difference in the number of shots white and blacks received in each state.&lt;/P&gt;</description>
      <pubDate>Fri, 21 Apr 2017 01:53:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-conditionally-check-the-difference-between-rows/m-p/351971#M82009</guid>
      <dc:creator>renjithr</dc:creator>
      <dc:date>2017-04-21T01:53:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to conditionally check the difference between rows?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-conditionally-check-the-difference-between-rows/m-p/351988#M82016</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input RACE :$12. STATE :$12. vaccinated_cnt DATE :anydtdte.;
format date yymm7.;
datalines;
WHITE	CALIFORNIA	2	Sep2016
WHITE	ARIZONA	1	Sep2016
WHITE	TEXAS	50	Oct2016
BLACK	CALIFORNIA	1	Sep2016
BLACK	ARIZONA	5	Sep2016
BLACK	TEXAS	10	Oct2016
;

proc sql;
create table cnt_diff as
select
    a.state, 
    a.date, 
    a.race,
    b.race as other_race,
    a.vaccinated_cnt - b.vaccinated_cnt as vaccinated_diff
from 
    have as a inner join
    have as b on a.state=b.state and a.date=b.date and a.race ne b.race
order by state, date, race, other_race;
select * from cnt_diff;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 21 Apr 2017 02:55:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-conditionally-check-the-difference-between-rows/m-p/351988#M82016</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2017-04-21T02:55:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to conditionally check the difference between rows?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-conditionally-check-the-difference-between-rows/m-p/351995#M82018</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input  Race $ Shot_rcvd  Area : $20.;
cards;
WHITE 10             CALIFORNIA
WHITE 20             ARIZONA
BLACK 21            CALIFORNIA
BLACK 5              ARIZONA
;
run;
data white(index=(area)) black(index=(area));
 set have;
 if race='WHITE' then output white;
  else if race='BLACK' then output black;
run;
data want;
 merge white black(keep=shot_rcvd area rename=(shot_rcvd=_shot));
 by area;
 diff=shot_rcvd-_shot;
 output;
 diff=-diff;
 race='BLACK';
 output;
 drop _shot;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 21 Apr 2017 03:10:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-conditionally-check-the-difference-between-rows/m-p/351995#M82018</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-04-21T03:10:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to conditionally check the difference between rows?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-conditionally-check-the-difference-between-rows/m-p/353412#M82500</link>
      <description>&lt;P&gt;Thank you all for your suggestions!&lt;/P&gt;</description>
      <pubDate>Tue, 25 Apr 2017 19:29:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-conditionally-check-the-difference-between-rows/m-p/353412#M82500</guid>
      <dc:creator>renjithr</dc:creator>
      <dc:date>2017-04-25T19:29:48Z</dc:date>
    </item>
  </channel>
</rss>

