<?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 Pulling a value from a list and matching it to an observation in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Pulling-a-value-from-a-list-and-matching-it-to-an-observation/m-p/300186#M63378</link>
    <description>&lt;P&gt;I think this is fairly straightforward; my brain just can't solve this problem right now:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;A) I have a&amp;nbsp;large SAS dataset of patients and it contains the villages that they each come from to get to clinic.&amp;nbsp;&lt;/P&gt;&lt;P&gt;B) I have a long list of distances from the village to the clinic.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need SAS to help me pull the distance from List B and put it into Dataset A.&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do I do that? Thank you!&lt;/P&gt;</description>
    <pubDate>Thu, 22 Sep 2016 18:44:11 GMT</pubDate>
    <dc:creator>rogersaj</dc:creator>
    <dc:date>2016-09-22T18:44:11Z</dc:date>
    <item>
      <title>Pulling a value from a list and matching it to an observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pulling-a-value-from-a-list-and-matching-it-to-an-observation/m-p/300186#M63378</link>
      <description>&lt;P&gt;I think this is fairly straightforward; my brain just can't solve this problem right now:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;A) I have a&amp;nbsp;large SAS dataset of patients and it contains the villages that they each come from to get to clinic.&amp;nbsp;&lt;/P&gt;&lt;P&gt;B) I have a long list of distances from the village to the clinic.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need SAS to help me pull the distance from List B and put it into Dataset A.&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do I do that? Thank you!&lt;/P&gt;</description>
      <pubDate>Thu, 22 Sep 2016 18:44:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pulling-a-value-from-a-list-and-matching-it-to-an-observation/m-p/300186#M63378</guid>
      <dc:creator>rogersaj</dc:creator>
      <dc:date>2016-09-22T18:44:11Z</dc:date>
    </item>
    <item>
      <title>Re: Pulling a value from a list and matching it to an observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pulling-a-value-from-a-list-and-matching-it-to-an-observation/m-p/300193#M63382</link>
      <description>&lt;P&gt;This is a very common look up problem. One solution is to use Proc SQL to join things on a key value.&lt;/P&gt;
&lt;P&gt;Here is a brief example.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data distance;
   input village $ clinic $ distance;
datalines;
A  Z 25
A  Y 30
A  X 60
B  Z 18
B  Y 28
B  X 12
;
run;

data visit;
   input patient Village $ Clinic $;
datalines;
1  A  Z
2  A  Y
3  B  Z
4  B  X
6  A  Z
;
run;

proc sql;
   create table matched as
   select visit.patient, visit.Village, visit.clinic,
          Distance.distance
   from visit left join  distance on
        visit.village=distance.village and visit.clinic=distance.clinic
   ;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note the use of the construct datasetname&lt;STRONG&gt;.&lt;/STRONG&gt;variable to reference which table (dataset) a variable comes from.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since I am matching on equal values the case of letters and spelling have to match exactly. NAME is not the same as Name.&lt;/P&gt;
&lt;P&gt;So you may need to ensure that the spelling of the clinics and villages is the same everytime. If you think that the spelling is correct but may have differences is capital letter use then modfy the code to&lt;/P&gt;
&lt;P&gt;&lt;FONT face="SAS Monospace" size="2"&gt;upcase(visit.village)=upcase(distance.village) &lt;/FONT&gt;&lt;FONT color="#0000ff" face="SAS Monospace" size="2"&gt;and&lt;/FONT&gt;&lt;FONT face="SAS Monospace" size="2"&gt; upcase(visit.clinic)=upcase(distance.clinic)&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 22 Sep 2016 19:27:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pulling-a-value-from-a-list-and-matching-it-to-an-observation/m-p/300193#M63382</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-09-22T19:27:22Z</dc:date>
    </item>
  </channel>
</rss>

