<?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: Embed an if/then (Case) statement within an SQL join in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Embed-an-if-then-Case-statement-within-an-SQL-join/m-p/369451#M275582</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/64767"&gt;@brulard&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;Using a format is another option.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data table1;
  Input ID $ Name $;
  Datalines;
001 John
004 Marc
007 Jess
012 Peter
Run;

Data table2;
  Input ID $ Relationship $;
  Datalines;
001 0
004 2
007 0
012 2
Run;

proc format;
  value $relationship(default=11)
    0 = 'Primary'
    1 = 'Secondary'
    other='not defined'
    ;
quit;

Proc sql;
  create table sofar as
    Select a.*, put(b.relationship,$relationship.) as Relationship_Desc
      From table1 a,table2 b
        Where a.id=b.id;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 22 Jun 2017 12:17:28 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2017-06-22T12:17:28Z</dc:date>
    <item>
      <title>Embed an if/then (Case) statement within an SQL join</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Embed-an-if-then-Case-statement-within-an-SQL-join/m-p/369443#M275579</link>
      <description>&lt;P&gt;hi&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm joining two tables, where I'd like the content from var in column b to be translated into a text of my choice. Instead of my creating another step, can this be done in a single query?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example code below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the final output, I'd like my variable "relationship" to read "Primary" if "0", or "Secondary" if "2".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data table1;
Input ID $ Name $;
Datalines;
001 John
004 Marc
007 Jess
012 Peter
Run;

Data table2;
Input ID $ Relationship $ ;
Datalines;
001 0
004 2
007 0
012 2
Run;

Proc sql; create table sofar as
Select a.*,b.relationship
From table1 a,table2 b
Where a.id=b.id;quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Thu, 22 Jun 2017 12:00:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Embed-an-if-then-Case-statement-within-an-SQL-join/m-p/369443#M275579</guid>
      <dc:creator>brulard</dc:creator>
      <dc:date>2017-06-22T12:00:17Z</dc:date>
    </item>
    <item>
      <title>Re: Embed an if/then (Case) statement within an SQL join</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Embed-an-if-then-Case-statement-within-an-SQL-join/m-p/369448#M275580</link>
      <description>&lt;P&gt;Use the case construct:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table sofar as
  select
    a.*,
    case
      when b.relationship = '0' then 'Primary'
      when b.relationship = '2' then 'Secondary'
      else 'Undefined'
    end as relationship
  from table1 a,table2 b
  where a.id=b.id
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or create a value format and assign it to relationship: &lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format library=work;
value $rel
  '0' = 'Primary'
  '2' = 'Secondary'
  other = 'Undefined'
;
run;

proc sql;
create table sofar2 as
  select
    a.*,
    b.relationship format = $rel.
  from table1 a,table2 b
  where a.id=b.id
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 22 Jun 2017 12:11:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Embed-an-if-then-Case-statement-within-an-SQL-join/m-p/369448#M275580</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-06-22T12:11:41Z</dc:date>
    </item>
    <item>
      <title>Re: Embed an if/then (Case) statement within an SQL join</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Embed-an-if-then-Case-statement-within-an-SQL-join/m-p/369449#M275581</link>
      <description>&lt;P&gt;something like this&lt;/P&gt;
&lt;PRE&gt;Proc sql; create table sofar as
Select a.*, 
      case when b.relationship ="0" then "Primary"
           when b.relationship ="2" then "Secondary"
	  else 'missing'
	  end as relationship
From table1 a,table2 b
Where a.id=b.id;
quit;
&lt;/PRE&gt;</description>
      <pubDate>Thu, 22 Jun 2017 12:10:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Embed-an-if-then-Case-statement-within-an-SQL-join/m-p/369449#M275581</guid>
      <dc:creator>kiranv_</dc:creator>
      <dc:date>2017-06-22T12:10:29Z</dc:date>
    </item>
    <item>
      <title>Re: Embed an if/then (Case) statement within an SQL join</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Embed-an-if-then-Case-statement-within-an-SQL-join/m-p/369451#M275582</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/64767"&gt;@brulard&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;Using a format is another option.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data table1;
  Input ID $ Name $;
  Datalines;
001 John
004 Marc
007 Jess
012 Peter
Run;

Data table2;
  Input ID $ Relationship $;
  Datalines;
001 0
004 2
007 0
012 2
Run;

proc format;
  value $relationship(default=11)
    0 = 'Primary'
    1 = 'Secondary'
    other='not defined'
    ;
quit;

Proc sql;
  create table sofar as
    Select a.*, put(b.relationship,$relationship.) as Relationship_Desc
      From table1 a,table2 b
        Where a.id=b.id;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 22 Jun 2017 12:17:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Embed-an-if-then-Case-statement-within-an-SQL-join/m-p/369451#M275582</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2017-06-22T12:17:28Z</dc:date>
    </item>
  </channel>
</rss>

