<?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: Proq SQL left join and changes in the table in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Proq-SQL-left-join-and-changes-in-the-table/m-p/813769#M321201</link>
    <description>&lt;P&gt;You could use a `CASE WHEN` statement to get what you want, but as &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt; said, we need example data before we can even provide you an accurate answer.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;case when x.type = 'Char' then 'No KS is estimated' else '' end as Notes&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You also can select the variables in the order that you want them, and then insert the `CASE WHEN` as the last statement before your `FROM` clause.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Again, I'm not confident in my answer without example data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/" target="_self"&gt;This&lt;/A&gt; macro converts your existing data into a DATA step that you can post with the SAS code button in your posts. Make sure there's nothing confidential, or simulate your data somehow.&lt;/P&gt;</description>
    <pubDate>Tue, 17 May 2022 12:02:55 GMT</pubDate>
    <dc:creator>maguiremq</dc:creator>
    <dc:date>2022-05-17T12:02:55Z</dc:date>
    <item>
      <title>Proq SQL left join and changes in the table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proq-SQL-left-join-and-changes-in-the-table/m-p/813742#M321185</link>
      <description>&lt;P&gt;i use the proc sql in a macro to merge multiple tables. The code works but i need to&amp;nbsp; make some adjustments&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to adjust the code in order the "Report" from the proc sql&amp;nbsp; to include the below :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1) When the Type in PSI_POP has the value "C" I want to add in the variable "N" the text "No KS is estimated"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2) In addition, i want to reorder the variables with variable "N" move to the end as "N" stands for Notes&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;thanks&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data PSI_POP;
   input Variable $ Type $ Period $ PSI 1. N $3.;
   datalines;
var1 N A 1 Y
var2 C A 2 .
var3 N A 1 .
var4 C A 2 .
;
run;

data KS_POP;
     input Variable $ Type $ Period $ KS 1. N $3.;
     datalines;
var1 N A 0 .
var2 C A 3 .
var4 C A 1 .
;
run;


proc sql;
create table report  as
 select * from PSI_POP as x left join KS_POP as y
 on x.Variable =y.Variable and x.Period =y.Period;
quit;&lt;/PRE&gt;</description>
      <pubDate>Tue, 17 May 2022 13:37:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proq-SQL-left-join-and-changes-in-the-table/m-p/813742#M321185</guid>
      <dc:creator>Toni2</dc:creator>
      <dc:date>2022-05-17T13:37:08Z</dc:date>
    </item>
    <item>
      <title>Re: Proq SQL left join and changes in the table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proq-SQL-left-join-and-changes-in-the-table/m-p/813744#M321186</link>
      <description>&lt;P&gt;Even if you would provide the perfect and exhaustive description of what you have and what you need, it would still be hard for many of us to provide you with actually working code without sample data allowing us to first test what we propose.&lt;/P&gt;
&lt;P&gt;Please provide sample data created in the form of working SAS data steps and then show us the desired result using this sample data.&lt;/P&gt;</description>
      <pubDate>Tue, 17 May 2022 10:39:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proq-SQL-left-join-and-changes-in-the-table/m-p/813744#M321186</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2022-05-17T10:39:17Z</dc:date>
    </item>
    <item>
      <title>Re: Proq SQL left join and changes in the table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proq-SQL-left-join-and-changes-in-the-table/m-p/813769#M321201</link>
      <description>&lt;P&gt;You could use a `CASE WHEN` statement to get what you want, but as &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt; said, we need example data before we can even provide you an accurate answer.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;case when x.type = 'Char' then 'No KS is estimated' else '' end as Notes&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You also can select the variables in the order that you want them, and then insert the `CASE WHEN` as the last statement before your `FROM` clause.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Again, I'm not confident in my answer without example data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/" target="_self"&gt;This&lt;/A&gt; macro converts your existing data into a DATA step that you can post with the SAS code button in your posts. Make sure there's nothing confidential, or simulate your data somehow.&lt;/P&gt;</description>
      <pubDate>Tue, 17 May 2022 12:02:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proq-SQL-left-join-and-changes-in-the-table/m-p/813769#M321201</guid>
      <dc:creator>maguiremq</dc:creator>
      <dc:date>2022-05-17T12:02:55Z</dc:date>
    </item>
    <item>
      <title>Re: Proq SQL left join and changes in the table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proq-SQL-left-join-and-changes-in-the-table/m-p/813790#M321214</link>
      <description>&lt;P&gt;Since using the asterisk in a join like yours is &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;VERY BAD CODING STYLE&lt;/STRONG&gt;&lt;/FONT&gt;&amp;nbsp;(as reflected by the WARNING in the log), you must replace it with the comprehensive list of variables anyway, and this allows you to do the change in variable order.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For question one, use a &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/sqlproc/n0a85s0ijz65irn1h3jtariooea5.htm" target="_blank" rel="noopener"&gt;CASE Expression&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 May 2022 13:14:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proq-SQL-left-join-and-changes-in-the-table/m-p/813790#M321214</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-05-17T13:14:23Z</dc:date>
    </item>
    <item>
      <title>Re: Proq SQL left join and changes in the table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proq-SQL-left-join-and-changes-in-the-table/m-p/813797#M321220</link>
      <description>thanks. You are right. i have edited my initial post adding some data - i hope it helps</description>
      <pubDate>Tue, 17 May 2022 13:39:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proq-SQL-left-join-and-changes-in-the-table/m-p/813797#M321220</guid>
      <dc:creator>Toni2</dc:creator>
      <dc:date>2022-05-17T13:39:27Z</dc:date>
    </item>
    <item>
      <title>Re: Proq SQL left join and changes in the table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proq-SQL-left-join-and-changes-in-the-table/m-p/813800#M321222</link>
      <description>thanks - i have now edited my initial post - please if you can have a look and advise</description>
      <pubDate>Tue, 17 May 2022 13:40:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proq-SQL-left-join-and-changes-in-the-table/m-p/813800#M321222</guid>
      <dc:creator>Toni2</dc:creator>
      <dc:date>2022-05-17T13:40:22Z</dc:date>
    </item>
    <item>
      <title>Re: Proq SQL left join and changes in the table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proq-SQL-left-join-and-changes-in-the-table/m-p/813802#M321224</link>
      <description>hi thanks for your comments&lt;BR /&gt;&lt;BR /&gt;For the warning i added the list with variables and works.&lt;BR /&gt;&lt;BR /&gt;For my question one, my problem is i don't know how to combine "left join" with "case" in one SQL &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Tue, 17 May 2022 13:55:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proq-SQL-left-join-and-changes-in-the-table/m-p/813802#M321224</guid>
      <dc:creator>Toni2</dc:creator>
      <dc:date>2022-05-17T13:55:42Z</dc:date>
    </item>
    <item>
      <title>Re: Proq SQL left join and changes in the table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proq-SQL-left-join-and-changes-in-the-table/m-p/813804#M321225</link>
      <description>&lt;P&gt;So you join on variable and period, but you have two more columns in common: type and n.&lt;/P&gt;
&lt;P&gt;Which of these should be used in the query?&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;Assuming&lt;/EM&gt; that you want them from the psi_pop table, here's how to do it:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table report as
  select
    p.variable,
    p.type,
    p.period,
    p.psi,
    k.ks,
    case
      when p.type = "C"
      then "No KS is estimated"
      else p.n
    end as N
  from psi_pop p left join ks_pop k
  on p.variable = k.variable and p.period = k.period
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 17 May 2022 14:03:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proq-SQL-left-join-and-changes-in-the-table/m-p/813804#M321225</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-05-17T14:03:30Z</dc:date>
    </item>
    <item>
      <title>Re: Proq SQL left join and changes in the table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proq-SQL-left-join-and-changes-in-the-table/m-p/813838#M321246</link>
      <description>thanks, quick questions, how can i add an additional case when in the above?</description>
      <pubDate>Tue, 17 May 2022 15:18:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proq-SQL-left-join-and-changes-in-the-table/m-p/813838#M321246</guid>
      <dc:creator>Toni2</dc:creator>
      <dc:date>2022-05-17T15:18:53Z</dc:date>
    </item>
    <item>
      <title>Re: Proq SQL left join and changes in the table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proq-SQL-left-join-and-changes-in-the-table/m-p/813843#M321248</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/372747"&gt;@Toni2&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;thanks, quick questions, how can i add an additional case when in the above?&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Like any other item in the SELECT. The CASE-END block is an expression like a calculation or a variable name.&lt;/P&gt;</description>
      <pubDate>Tue, 17 May 2022 15:34:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proq-SQL-left-join-and-changes-in-the-table/m-p/813843#M321248</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-05-17T15:34:48Z</dc:date>
    </item>
  </channel>
</rss>

