<?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: Lookup using PROC SQL in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Lookup-using-PROC-SQL/m-p/314544#M68522</link>
    <description>&lt;P&gt;&lt;SPAN&gt;Multithreading is when SAS splits a task among many processors that run in parallel. I don't know exactly why your code reordered the data table and mine didn't. To my knowledge, this isn't documented anywhere and might change in a future SAS version. I agree 100% with&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13674"&gt;@LinusH﻿&lt;/a&gt;'s comment below.&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Sun, 27 Nov 2016 04:20:55 GMT</pubDate>
    <dc:creator>PGStats</dc:creator>
    <dc:date>2016-11-27T04:20:55Z</dc:date>
    <item>
      <title>Lookup using PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Lookup-using-PROC-SQL/m-p/313332#M68059</link>
      <description>&lt;P&gt;My following PROC SQL sort the common variable I joined the table with. Is there a code for lookup table where the common variable (Country_Code in this case) does not get sorted?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My expected output:&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Emp_Name Country Code&lt;/STRONG&gt;&lt;BR /&gt;David &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Japan&lt;BR /&gt;Joy &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;France&lt;BR /&gt;Murad &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;India&lt;BR /&gt;Paul &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Italy&lt;BR /&gt;Vick &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;USA&lt;BR /&gt;Maya &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; France&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA Lookup_CountryCode;
INPUT Country_Name $ Country_Code Region $;
DATALINES;
Japan 107 Asia
USA 109 America
France 103 Europe
Canada 111 America
India 105 Asia
Nepal 115 Asia
Italy 102 Europe
;
RUN;


DATA Employee;
INPUT Emp_Name $ Country_Code;
DATALINES;
David 107
Joy 103
Murad 105
Paul 102
Vick 109
Maya 103
;
RUN;


PROC SQL;
CREATE TABLE want AS
SELECT a.Emp_Name, b.Country_Name 
FROM Employee a LEFT JOIN Lookup_CountryCode b
on a.Country_Code=b.Country_Code;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 22 Nov 2016 03:27:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Lookup-using-PROC-SQL/m-p/313332#M68059</guid>
      <dc:creator>mlogan</dc:creator>
      <dc:date>2016-11-22T03:27:48Z</dc:date>
    </item>
    <item>
      <title>Re: Lookup using PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Lookup-using-PROC-SQL/m-p/313335#M68061</link>
      <description>&lt;P&gt;You can't control row order with SQL unless you use an &lt;EM&gt;order by&lt;/EM&gt; clause.&lt;/P&gt;
&lt;P&gt;You must use a data step, or add a sorting variable.&lt;/P&gt;</description>
      <pubDate>Tue, 22 Nov 2016 03:36:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Lookup-using-PROC-SQL/m-p/313335#M68061</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2016-11-22T03:36:58Z</dc:date>
    </item>
    <item>
      <title>Re: Lookup using PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Lookup-using-PROC-SQL/m-p/313338#M68063</link>
      <description>&lt;P&gt;I tried this and it worked:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
CREATE TABLE want AS
SELECT a.Emp_Name, 
    (   select Country_Name 
        from Lookup_CountryCode 
        where Country_Code = a.Country_Code  ) as country_name
FROM Employee as a;
select * from want;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 22 Nov 2016 03:48:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Lookup-using-PROC-SQL/m-p/313338#M68063</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-11-22T03:48:00Z</dc:date>
    </item>
    <item>
      <title>Re: Lookup using PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Lookup-using-PROC-SQL/m-p/313340#M68065</link>
      <description>&lt;P&gt;You could also create formats and then apply them to your dataset. You can apply your formats and not modify your dataset unless you need both, code and name.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Nov 2016 03:51:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Lookup-using-PROC-SQL/m-p/313340#M68065</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-11-22T03:51:23Z</dc:date>
    </item>
    <item>
      <title>Re: Lookup using PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Lookup-using-PROC-SQL/m-p/313349#M68073</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/462"&gt;@PGStats﻿&lt;/a&gt; Maybe add option&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql nothreads;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;to ensure that multithreading is off, otherwise there is no way to be sure that row order is kept as is.&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Nov 2016 04:20:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Lookup-using-PROC-SQL/m-p/313349#M68073</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2016-11-22T04:20:18Z</dc:date>
    </item>
    <item>
      <title>Re: Lookup using PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Lookup-using-PROC-SQL/m-p/313352#M68076</link>
      <description>&lt;P&gt;Yeah. I can imagine (but not test) that multithreading would disturb output order. Anyway, output order is never guaranteed unless there is an ORDER BY clause.&lt;/P&gt;</description>
      <pubDate>Tue, 22 Nov 2016 04:51:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Lookup-using-PROC-SQL/m-p/313352#M68076</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-11-22T04:51:41Z</dc:date>
    </item>
    <item>
      <title>Re: Lookup using PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Lookup-using-PROC-SQL/m-p/313359#M68078</link>
      <description>&lt;P&gt;By a data step it can be achieved.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hold the Country_Name in a temporary array using Country_Code as its Index. Then read a record by record from Lookup_Country data set, load the array. Then lookup the array using Country_Code from Employee. If Country_Code is found in Lookup_CountryCode data set &amp;nbsp;then the coreesponding cell will have Country_Name, otherwise a missing value. Thus the order of rows of Employee is undisturbed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data need;
   array k[102:115] $8 _temporary_;
   length Emp_Name $8;
   do until(eof);
      set Lookup_CountryCode(drop = Region) end = eof;
      k[Country_Code] = Country_Name;
   end;

   do until(last);
      set Employee end = last;
      if not missing (k[Country_Code]) then do;
         Country_Name = k[Country_Code];
         output;
      end;
   end;
drop Country_Code;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Nov 2016 05:46:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Lookup-using-PROC-SQL/m-p/313359#M68078</guid>
      <dc:creator>KachiM</dc:creator>
      <dc:date>2016-11-22T05:46:22Z</dc:date>
    </item>
    <item>
      <title>Re: Lookup using PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Lookup-using-PROC-SQL/m-p/313377#M68087</link>
      <description>&lt;P&gt;This is how you do it with a format:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data cntlin;
set lookup_countrycode;
drop region;
fmtname = 'country_lookup';
type = 'N';
rename
  country_code=start
  country_name=label
;
run;

proc format library=work cntlin=cntlin;
run;

data want;
set employee;
country_name = put(country_code,country_lookup.);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 22 Nov 2016 08:29:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Lookup-using-PROC-SQL/m-p/313377#M68087</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-11-22T08:29:35Z</dc:date>
    </item>
    <item>
      <title>Re: Lookup using PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Lookup-using-PROC-SQL/m-p/313406#M68097</link>
      <description>&lt;P&gt;Original sort order is not a sustainable concept when transforming data. if your original sort order is important, you need a columns/variable that gives you the appropriate sort order (which you could use to sort the result after the processing, like in an ORDER BY clause&amp;nbsp;in SQL).&lt;/P&gt;</description>
      <pubDate>Tue, 22 Nov 2016 10:32:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Lookup-using-PROC-SQL/m-p/313406#M68097</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2016-11-22T10:32:22Z</dc:date>
    </item>
    <item>
      <title>Re: Lookup using PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Lookup-using-PROC-SQL/m-p/314527#M68514</link>
      <description>Hi PG,&lt;BR /&gt;Thanks for your help.&lt;BR /&gt;What is multithreading? &lt;BR /&gt;In which case your code is going to fail?&lt;BR /&gt;Thanks,&lt;BR /&gt;</description>
      <pubDate>Sun, 27 Nov 2016 02:34:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Lookup-using-PROC-SQL/m-p/314527#M68514</guid>
      <dc:creator>mlogan</dc:creator>
      <dc:date>2016-11-27T02:34:20Z</dc:date>
    </item>
    <item>
      <title>Re: Lookup using PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Lookup-using-PROC-SQL/m-p/314544#M68522</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Multithreading is when SAS splits a task among many processors that run in parallel. I don't know exactly why your code reordered the data table and mine didn't. To my knowledge, this isn't documented anywhere and might change in a future SAS version. I agree 100% with&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13674"&gt;@LinusH﻿&lt;/a&gt;'s comment below.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 27 Nov 2016 04:20:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Lookup-using-PROC-SQL/m-p/314544#M68522</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-11-27T04:20:55Z</dc:date>
    </item>
  </channel>
</rss>

