<?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: Converting CASE WHEN(Proc SQL) into Data Step hash object lookup in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Converting-CASE-WHEN-Proc-SQL-into-Data-Step-hash-object-lookup/m-p/545143#M150776</link>
    <description>&lt;P&gt;Both steps you posted are not error-free and are using different datasets and variables, please fix these problems.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In a data step select/case would be replaced by select/when. The left join can be written as merge with by and in.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 22 Mar 2019 07:00:53 GMT</pubDate>
    <dc:creator>andreas_lds</dc:creator>
    <dc:date>2019-03-22T07:00:53Z</dc:date>
    <item>
      <title>Converting CASE WHEN(Proc SQL) into Data Step hash object lookup</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-CASE-WHEN-Proc-SQL-into-Data-Step-hash-object-lookup/m-p/545136#M150774</link>
      <description>&lt;P&gt;Hi SAS Community. I am trying to convert PROC SQL statement with some columns having CASE WHEN statement into Data step hash object lookup for neater looking and some other factors set by my team.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the challenge that I am facing. There are some CASE WHEN statement that is actually taking from multiple sources. For example:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;

create table a as

select&amp;nbsp;

case when type eq 'PMU' then Lng=ppp.Lng

when type eq 'PPU' then Lng=yyy.Lng

end as Lng

from b left join c

on b.Id=c.Id;

;

quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My Data Step Hash Object lookup will look something like this without the CASE WHEN statement, which i want to include in but dont know how.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data SimResultCapLoad;
	
  if _n_=1 then do;
     declare hash h(dataset:"c)");
     h.definekey('Id');
     h.definedata('Lng');
     h.definedone();

  end;
  set netcap.SimResultCapLoad;

  *Lookup;
  rc=h.find();

run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;But how do i add the checking of CASE WHEN in?&lt;/P&gt;</description>
      <pubDate>Fri, 22 Mar 2019 06:36:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-CASE-WHEN-Proc-SQL-into-Data-Step-hash-object-lookup/m-p/545136#M150774</guid>
      <dc:creator>imdickson</dc:creator>
      <dc:date>2019-03-22T06:36:34Z</dc:date>
    </item>
    <item>
      <title>Re: Converting CASE WHEN(Proc SQL) into Data Step hash object lookup</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-CASE-WHEN-Proc-SQL-into-Data-Step-hash-object-lookup/m-p/545141#M150775</link>
      <description>&lt;P&gt;Your SQL is syntactically incorrect. You use table aliases ppp and yyy, but there are no tables for these in the from part.&lt;/P&gt;</description>
      <pubDate>Fri, 22 Mar 2019 06:54:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-CASE-WHEN-Proc-SQL-into-Data-Step-hash-object-lookup/m-p/545141#M150775</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-03-22T06:54:50Z</dc:date>
    </item>
    <item>
      <title>Re: Converting CASE WHEN(Proc SQL) into Data Step hash object lookup</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-CASE-WHEN-Proc-SQL-into-Data-Step-hash-object-lookup/m-p/545143#M150776</link>
      <description>&lt;P&gt;Both steps you posted are not error-free and are using different datasets and variables, please fix these problems.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In a data step select/case would be replaced by select/when. The left join can be written as merge with by and in.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Mar 2019 07:00:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-CASE-WHEN-Proc-SQL-into-Data-Step-hash-object-lookup/m-p/545143#M150776</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2019-03-22T07:00:53Z</dc:date>
    </item>
    <item>
      <title>Re: Converting CASE WHEN(Proc SQL) into Data Step hash object lookup</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-CASE-WHEN-Proc-SQL-into-Data-Step-hash-object-lookup/m-p/545211#M150794</link>
      <description>&lt;P&gt;You need to provide more details about what you are trying to do and include some simple example datasets to make it clearer.&lt;/P&gt;
&lt;P&gt;From your brief explanation you probably just want to create formats from your different lookup tables.&lt;/P&gt;
&lt;P&gt;Then you can use the PUTN() function to dynamically pick which format to use.&lt;/P&gt;
&lt;P&gt;Even easier if you make the format names match the value of the TYPE variable.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data A;
  set B;
  LNG = putn(id,cats(type,'.'));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If your ID variable is character then use PUTC() function instead and add $ prefix on the format names.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Mar 2019 13:10:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-CASE-WHEN-Proc-SQL-into-Data-Step-hash-object-lookup/m-p/545211#M150794</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-03-22T13:10:55Z</dc:date>
    </item>
    <item>
      <title>Re: Converting CASE WHEN(Proc SQL) into Data Step hash object lookup</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-CASE-WHEN-Proc-SQL-into-Data-Step-hash-object-lookup/m-p/545406#M150872</link>
      <description>&lt;P&gt;Personally I don't see any point in switching to hash look-ups unless you are gaining a clear functional or performance advantage.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt; 's look-up format approach is way easier to code and is as fast as hash look-ups in many circumstances.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have DATA steps doing 30 plus format look-ups. There is no way you would ever want to code those using hashes unless you enjoy writing 10 times the amount of code. I also (very rarely) use hash but only when there is a clear advantage in doing so.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 23 Mar 2019 01:24:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-CASE-WHEN-Proc-SQL-into-Data-Step-hash-object-lookup/m-p/545406#M150872</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2019-03-23T01:24:45Z</dc:date>
    </item>
    <item>
      <title>Re: Converting CASE WHEN(Proc SQL) into Data Step hash object lookup</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-CASE-WHEN-Proc-SQL-into-Data-Step-hash-object-lookup/m-p/545408#M150874</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/63520"&gt;@imdickson&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In a data step you'd address the CASE/WHEN syntax with an IF/THEN - and you lookup/assign values based of the outcome of this condition.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The (syntactically incorrect) SQL you've posted has a left join in it. So here if the relationship between the tables is 1:n with the table to the left having the n matching rows then a simple hash lookup won't do anymore but you need also to loop using the hash do_over method.&lt;/P&gt;</description>
      <pubDate>Sat, 23 Mar 2019 01:59:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-CASE-WHEN-Proc-SQL-into-Data-Step-hash-object-lookup/m-p/545408#M150874</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-03-23T01:59:29Z</dc:date>
    </item>
    <item>
      <title>Re: Converting CASE WHEN(Proc SQL) into Data Step hash object lookup</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-CASE-WHEN-Proc-SQL-into-Data-Step-hash-object-lookup/m-p/545683#M151012</link>
      <description>&lt;P&gt;Hi everyone. I've figured out the way to do it. What i need to do is to add "If then else" condition after "a.find()" statement.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It is now working fine. Thanks everyone for trying to help me out there. Cheers.&lt;/P&gt;</description>
      <pubDate>Mon, 25 Mar 2019 04:01:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-CASE-WHEN-Proc-SQL-into-Data-Step-hash-object-lookup/m-p/545683#M151012</guid>
      <dc:creator>imdickson</dc:creator>
      <dc:date>2019-03-25T04:01:46Z</dc:date>
    </item>
  </channel>
</rss>

