<?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: Matching rows in two columns using a loop in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Matching-rows-in-two-columns-using-a-loop/m-p/288000#M59330</link>
    <description>&lt;P&gt;Where would the names be if not in SAS?&lt;/P&gt;
&lt;P&gt;This is a dodgy process. I think I'll be more comfortable staying out of it actually.&lt;/P&gt;</description>
    <pubDate>Thu, 28 Jul 2016 22:52:25 GMT</pubDate>
    <dc:creator>ChrisNZ</dc:creator>
    <dc:date>2016-07-28T22:52:25Z</dc:date>
    <item>
      <title>Matching rows in two columns using a loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Matching-rows-in-two-columns-using-a-loop/m-p/287972#M59314</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Hi,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I’m trying to determine the race of subjects in my dataset based on their last name. I have a list of last names that indicate a given race. My dataset looks something like this:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;White_name&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Subject_name &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Race&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Johnson&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Appleby&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; White&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;MacDonald&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Brians&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; White&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Burns&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; MacDonald&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [blank]&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Manning&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Murphy &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;White&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;STRONG&gt;White_name&lt;/STRONG&gt; represents a databank of all potential white last names.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;STRONG&gt;Subject_name&lt;/STRONG&gt; represents the last name of the subjects in my sample.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;STRONG&gt;Race&lt;/STRONG&gt; is a partially complete variable with information on their race. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I would like to fill in the blanks in the Race variable based on the Subject_name being found in the White_name list.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;My logic would flow something like this:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;if subject_name=any of the White_name then race2=’White’; else race2=race;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;However, I believe I need to loop through all the names in the White_name variable in order to find a match. Note that I have a large cohort with many repetitions of last names.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Would appreciate any help! Please note that I am a very new SAS user!&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thank you!&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Jul 2016 21:40:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Matching-rows-in-two-columns-using-a-loop/m-p/287972#M59314</guid>
      <dc:creator>Shinypants</dc:creator>
      <dc:date>2016-07-28T21:40:48Z</dc:date>
    </item>
    <item>
      <title>Re: Matching rows in two columns using a loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Matching-rows-in-two-columns-using-a-loop/m-p/287982#M59322</link>
      <description>&lt;P&gt;I assume you have a dataset that maps the names to race?&lt;/P&gt;
&lt;P&gt;I would recommend proc format, using the dataset to create your format and then apply it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's a paper that's worth reading regarding proc format.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;FYI, this method of assigning race by last names is flawed beyond belief and has been thoroughly shown to be incorrect and unreliable.&lt;/STRONG&gt; &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data lookup;
informat name race $20.;
input name $ race $;
cards;
Johnson White
McDonald White
Burns White
Ortez Mexican
;
run;


data have;
input name $20.;
cards;
Johnson
McDonald
Burns 
Ortez
Wrong
;
run;

data create_format;
set lookup end=last;
fmtname='NameToRace';
type='C';
start=name;
label=race;

if last then do;
	output;
	hlo='O';
	label='Other';
	output;
end;
else output;
run;

proc format cntlin=create_format;
run;

data want;
set have;

race=put(name, $NameToRace.);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 28 Jul 2016 22:25:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Matching-rows-in-two-columns-using-a-loop/m-p/287982#M59322</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-07-28T22:25:15Z</dc:date>
    </item>
    <item>
      <title>Re: Matching rows in two columns using a loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Matching-rows-in-two-columns-using-a-loop/m-p/287983#M59323</link>
      <description>&lt;P&gt;The use of Proc Format or Hash Objects will be suitable for your problem. I advise you to read on &lt;STRONG&gt;creating Fornats from a Data Set&lt;/STRONG&gt; as Hash objects may be much for you now.&lt;/P&gt;</description>
      <pubDate>Thu, 28 Jul 2016 22:25:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Matching-rows-in-two-columns-using-a-loop/m-p/287983#M59323</guid>
      <dc:creator>KachiM</dc:creator>
      <dc:date>2016-07-28T22:25:32Z</dc:date>
    </item>
    <item>
      <title>Re: Matching rows in two columns using a loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Matching-rows-in-two-columns-using-a-loop/m-p/287984#M59324</link>
      <description>&lt;P&gt;I can't believe I am writing this. This would be totally illegal in some countries!&amp;nbsp;Race? Really?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Anyway, this may do:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data T;
infile cards missover;
input White_name $ Subject_name $ Race $;
cards;
Johnson       Appleby      White
MacDonald     Brians       White
Burns         MacDonald  
Manning       Murphy       White
xx            zz           
run;
proc sql;
  select a.*
        ,coalescec(b.RACE,a.RACE) as RACE2
   from T    a
   left join
        T b on a.Subject_name=b.White_name;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="SAS Monospace" size="1"&gt;&lt;FONT face="SAS Monospace" size="1"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;TABLE class="table" rules="all" frame="box" cellspacing="0" cellpadding="5" summary="Procedure SQL: Query Results"&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="l b header" scope="col"&gt;White_name&lt;/TH&gt;
&lt;TH class="l b header" scope="col"&gt;Subject_name&lt;/TH&gt;
&lt;TH class="l b header" scope="col"&gt;Race&lt;/TH&gt;
&lt;TH class="l b header" scope="col"&gt;RACE2&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;Johnson&lt;/TD&gt;
&lt;TD class="l data"&gt;Appleby&lt;/TD&gt;
&lt;TD class="l data"&gt;White&lt;/TD&gt;
&lt;TD class="l data"&gt;White&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;MacDonal&lt;/TD&gt;
&lt;TD class="l data"&gt;Brians&lt;/TD&gt;
&lt;TD class="l data"&gt;White&lt;/TD&gt;
&lt;TD class="l data"&gt;White&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;Burns&lt;/TD&gt;
&lt;TD class="l data"&gt;MacDonal&lt;/TD&gt;
&lt;TD class="l data"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD class="l data"&gt;White&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;Manning&lt;/TD&gt;
&lt;TD class="l data"&gt;Murphy&lt;/TD&gt;
&lt;TD class="l data"&gt;White&lt;/TD&gt;
&lt;TD class="l data"&gt;White&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;xx&lt;/TD&gt;
&lt;TD class="l data"&gt;zz&lt;/TD&gt;
&lt;TD class="l data"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD class="l data"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
      <pubDate>Thu, 28 Jul 2016 22:34:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Matching-rows-in-two-columns-using-a-loop/m-p/287984#M59324</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2016-07-28T22:34:08Z</dc:date>
    </item>
    <item>
      <title>Re: Matching rows in two columns using a loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Matching-rows-in-two-columns-using-a-loop/m-p/287994#M59327</link>
      <description>&lt;P&gt;Thank you for your response!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My data is quite large (8000+) names. Would this method require me to write all the names in SAS?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Jul 2016 22:43:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Matching-rows-in-two-columns-using-a-loop/m-p/287994#M59327</guid>
      <dc:creator>Shinypants</dc:creator>
      <dc:date>2016-07-28T22:43:58Z</dc:date>
    </item>
    <item>
      <title>Re: Matching rows in two columns using a loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Matching-rows-in-two-columns-using-a-loop/m-p/288000#M59330</link>
      <description>&lt;P&gt;Where would the names be if not in SAS?&lt;/P&gt;
&lt;P&gt;This is a dodgy process. I think I'll be more comfortable staying out of it actually.&lt;/P&gt;</description>
      <pubDate>Thu, 28 Jul 2016 22:52:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Matching-rows-in-two-columns-using-a-loop/m-p/288000#M59330</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2016-07-28T22:52:25Z</dc:date>
    </item>
    <item>
      <title>Re: Matching rows in two columns using a loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Matching-rows-in-two-columns-using-a-loop/m-p/288006#M59334</link>
      <description>&lt;P&gt;This project is designed to prove how unreliable it is to base race off last names.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My data are in an excel file which I have imported into SAS. It looks like in your code that you manually type in all those names. Is there any way to select the variable as a whole without typing out all the names in the code?&lt;/P&gt;</description>
      <pubDate>Thu, 28 Jul 2016 23:24:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Matching-rows-in-two-columns-using-a-loop/m-p/288006#M59334</guid>
      <dc:creator>Shinypants</dc:creator>
      <dc:date>2016-07-28T23:24:36Z</dc:date>
    </item>
    <item>
      <title>Re: Matching rows in two columns using a loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Matching-rows-in-two-columns-using-a-loop/m-p/288007#M59335</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ﻿&lt;/a&gt;&amp;nbsp;typed in lines of data to match your example data as you didn't provide that to us. The set that has the names you have already read into SAS can be used.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There may be some other issues on how to use your exact data as we do not have that but general approach is what was demonstrated.&lt;/P&gt;</description>
      <pubDate>Thu, 28 Jul 2016 23:34:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Matching-rows-in-two-columns-using-a-loop/m-p/288007#M59335</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-07-28T23:34:28Z</dc:date>
    </item>
    <item>
      <title>Re: Matching rows in two columns using a loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Matching-rows-in-two-columns-using-a-loop/m-p/288010#M59337</link>
      <description>&lt;P&gt;I typed in the names to generate a sample data set. Replace your dataset with the names of the sample datasets.&lt;/P&gt;</description>
      <pubDate>Fri, 29 Jul 2016 00:03:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Matching-rows-in-two-columns-using-a-loop/m-p/288010#M59337</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-07-29T00:03:32Z</dc:date>
    </item>
  </channel>
</rss>

