<?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 how to look up value for a newly created column from another table in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-look-up-value-for-a-newly-created-column-from-another/m-p/818766#M323199</link>
    <description>&lt;P&gt;Hi all, I am a beginner in SAS, so please bear with my question. Basically, I want to look up the value for my dataset from another dataset, but not sure how to do it in a faster way (as the data is millions). I tried using proc sql but it took very long and failed.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Let's say I created a new column for my current dataset as below:&lt;/P&gt;&lt;P&gt;let's say this dataset called 'abc'&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;customer&lt;/TD&gt;&lt;TD&gt;date&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;112&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;114&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;203&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;158&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then, the lookup dataset called 'lookup' is as below:&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;customer&lt;/TD&gt;&lt;TD&gt;date&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;112&lt;/TD&gt;&lt;TD&gt;201002&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;114&lt;/TD&gt;&lt;TD&gt;201004&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;203&lt;/TD&gt;&lt;TD&gt;201006&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;158&lt;/TD&gt;&lt;TD&gt;201007&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;203&lt;/TD&gt;&lt;TD&gt;200901&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;158&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;200704&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;As you can observe from the lookup table above, there are duplicate customer numbers with different dates. However, what I wanna do is to look up the earliest date from the lookup table and append them into the 'abc' dataset.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The below shows the expected output I wish to have for abc table:&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;customer&lt;/TD&gt;&lt;TD&gt;date&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;112&lt;/TD&gt;&lt;TD&gt;201002&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;114&lt;/TD&gt;&lt;TD&gt;201004&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;203&lt;/TD&gt;&lt;TD&gt;200901&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;158&lt;/TD&gt;&lt;TD&gt;200704&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Appreciate if anyone can help (this is million row dataset)&lt;/P&gt;</description>
    <pubDate>Fri, 17 Jun 2022 08:51:49 GMT</pubDate>
    <dc:creator>heretolearnSAS</dc:creator>
    <dc:date>2022-06-17T08:51:49Z</dc:date>
    <item>
      <title>how to look up value for a newly created column from another table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-look-up-value-for-a-newly-created-column-from-another/m-p/818766#M323199</link>
      <description>&lt;P&gt;Hi all, I am a beginner in SAS, so please bear with my question. Basically, I want to look up the value for my dataset from another dataset, but not sure how to do it in a faster way (as the data is millions). I tried using proc sql but it took very long and failed.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Let's say I created a new column for my current dataset as below:&lt;/P&gt;&lt;P&gt;let's say this dataset called 'abc'&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;customer&lt;/TD&gt;&lt;TD&gt;date&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;112&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;114&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;203&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;158&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then, the lookup dataset called 'lookup' is as below:&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;customer&lt;/TD&gt;&lt;TD&gt;date&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;112&lt;/TD&gt;&lt;TD&gt;201002&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;114&lt;/TD&gt;&lt;TD&gt;201004&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;203&lt;/TD&gt;&lt;TD&gt;201006&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;158&lt;/TD&gt;&lt;TD&gt;201007&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;203&lt;/TD&gt;&lt;TD&gt;200901&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;158&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;200704&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;As you can observe from the lookup table above, there are duplicate customer numbers with different dates. However, what I wanna do is to look up the earliest date from the lookup table and append them into the 'abc' dataset.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The below shows the expected output I wish to have for abc table:&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;customer&lt;/TD&gt;&lt;TD&gt;date&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;112&lt;/TD&gt;&lt;TD&gt;201002&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;114&lt;/TD&gt;&lt;TD&gt;201004&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;203&lt;/TD&gt;&lt;TD&gt;200901&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;158&lt;/TD&gt;&lt;TD&gt;200704&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Appreciate if anyone can help (this is million row dataset)&lt;/P&gt;</description>
      <pubDate>Fri, 17 Jun 2022 08:51:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-look-up-value-for-a-newly-created-column-from-another/m-p/818766#M323199</guid>
      <dc:creator>heretolearnSAS</dc:creator>
      <dc:date>2022-06-17T08:51:49Z</dc:date>
    </item>
    <item>
      <title>Re: how to look up value for a newly created column from another table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-look-up-value-for-a-newly-created-column-from-another/m-p/818809#M323224</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have1;
 input customer	date;
 cards;
112 .	 
114	. 
203	. 
158	. 
;

data have2;
 input customer	date :yymmn6.;
 format date yymmn6.;
 cards;
112	201002
114	201004
203	201006
158	201007
203	200901
158	200704
;


proc sql;
  create table want as
  select a.customer, b.date
  from have1 a left join have2 b
  on a.customer = b.customer
  group by a.customer
  having min(b.date) = b.date;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Jun 2022 12:47:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-look-up-value-for-a-newly-created-column-from-another/m-p/818809#M323224</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2022-06-17T12:47:53Z</dc:date>
    </item>
    <item>
      <title>Re: how to look up value for a newly created column from another table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-look-up-value-for-a-newly-created-column-from-another/m-p/818814#M323227</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data current;
input customer_number date : yymmn6.;
datalines;
112 . 
114 . 
203 . 
158 . 
;

data lookup;
input customer_number date : yymmn6.;
format date yymmn6.;
datalines;
112 201002 
114 201004 
203 201006 
158 201007 
203 200901 
158 200704 
;

proc sql;
   create table want as
   select c.customer_number
        , min_date format = yymmn6.
   from current c
   left join 
         (select customer_number
               , min(date) as min_date
          from lookup
          group by customer_number
         ) l
   on c.customer_number = l.customer_number
   ;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 17 Jun 2022 13:00:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-look-up-value-for-a-newly-created-column-from-another/m-p/818814#M323227</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-06-17T13:00:20Z</dc:date>
    </item>
  </channel>
</rss>

