<?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: Combine steps in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Combine-steps/m-p/807336#M318278</link>
    <description>&lt;P&gt;It's feasible but it's non-sense because the code becomes unreadable&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
     CREATE TABLE WORK.BASE(DROP=PLANT_DESC CNV_FCTR ALTN_UOM TGT_QTY BASE_UOM PLANNED_ZNL2 _ZNL_hlp) AS
     SELECT *
         ,A.TGT_QTY*B.CNV_FCTR AS PLANNED_ZNL2
         ,case 
            when _ZNL_hlp = . THEN PLANNED_ZNL2
            else _ZNL_hlp
         end as _ZNL
     FROM WORK.BASELINE AS A LEFT JOIN WORK.AT_UOM(rename=(_ZNL=_ZNL_hlp)) AS B
       ON A.MATRL_NBR = B.MATRL_NBR 
       AND A.BASE_UOM =B.BASE_UOM  
       AND B.ALTN_UOM = 'ZNL';
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;you need to rename the _ZNL variable because you can't add it twice to the dataset. (select *)&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292396"&gt;@David_Billa&lt;/a&gt;&amp;nbsp;make sure you always terminate proc sql with QUIT;&lt;/P&gt;</description>
    <pubDate>Tue, 12 Apr 2022 10:18:46 GMT</pubDate>
    <dc:creator>Oligolas</dc:creator>
    <dc:date>2022-04-12T10:18:46Z</dc:date>
    <item>
      <title>Combine steps</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combine-steps/m-p/807330#M318274</link>
      <description>&lt;PRE&gt;PROC SQL;
     CREATE TABLE WORK.BASE AS
     SELECT *
         ,A.TGT_QTY*B.CNV_FCTR AS PLANNED_ZNL2
     FROM WORK.BASELINE AS A LEFT JOIN WORK.AT_UOM AS B
       ON A.MATRL_NBR = B.MATRL_NBR 
       AND A.BASE_UOM =B.BASE_UOM  
       AND B.ALTN_UOM = 'ZNL';
RUN;

DATA WORK.BASE (DROP=PLANT_DESC CNV_FCTR
     ALTN_UOM TGT_QTY BASE_UOM PLANNED_ZNL2);
     SET WORK.BASE;
     IF _ZNL = . THEN _ZNL = PLANNED_ZNL2;
;
RUN;
&lt;/PRE&gt;
&lt;P&gt;Any help to combine the below two steps into one?&lt;/P&gt;</description>
      <pubDate>Tue, 12 Apr 2022 09:42:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combine-steps/m-p/807330#M318274</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2022-04-12T09:42:03Z</dc:date>
    </item>
    <item>
      <title>Re: Combine steps</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combine-steps/m-p/807335#M318277</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
     CREATE TABLE WORK.BASE AS
     SELECT *
          , A.TGT_QTY*B.CNV_FCTR AS PLANNED_ZNL2
		  , case when _ZNL = . then Planned else . end as _ZNL
     FROM WORK.BASELINE AS A LEFT JOIN WORK.AT_UOM AS B
       ON A.MATRL_NBR = B.MATRL_NBR 
       AND A.BASE_UOM =B.BASE_UOM  
       AND B.ALTN_UOM = 'ZNL';
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Unstested.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Apr 2022 10:10:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combine-steps/m-p/807335#M318277</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-04-12T10:10:15Z</dc:date>
    </item>
    <item>
      <title>Re: Combine steps</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combine-steps/m-p/807336#M318278</link>
      <description>&lt;P&gt;It's feasible but it's non-sense because the code becomes unreadable&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
     CREATE TABLE WORK.BASE(DROP=PLANT_DESC CNV_FCTR ALTN_UOM TGT_QTY BASE_UOM PLANNED_ZNL2 _ZNL_hlp) AS
     SELECT *
         ,A.TGT_QTY*B.CNV_FCTR AS PLANNED_ZNL2
         ,case 
            when _ZNL_hlp = . THEN PLANNED_ZNL2
            else _ZNL_hlp
         end as _ZNL
     FROM WORK.BASELINE AS A LEFT JOIN WORK.AT_UOM(rename=(_ZNL=_ZNL_hlp)) AS B
       ON A.MATRL_NBR = B.MATRL_NBR 
       AND A.BASE_UOM =B.BASE_UOM  
       AND B.ALTN_UOM = 'ZNL';
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;you need to rename the _ZNL variable because you can't add it twice to the dataset. (select *)&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292396"&gt;@David_Billa&lt;/a&gt;&amp;nbsp;make sure you always terminate proc sql with QUIT;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Apr 2022 10:18:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combine-steps/m-p/807336#M318278</guid>
      <dc:creator>Oligolas</dc:creator>
      <dc:date>2022-04-12T10:18:46Z</dc:date>
    </item>
    <item>
      <title>Re: Combine steps</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combine-steps/m-p/807341#M318293</link>
      <description>&lt;P&gt;&lt;STRONG&gt;DO NOT&lt;/STRONG&gt; use the asterisk like this. You have at least two variables in common between the two datasets, so SQL will throw a WARNING, and you may get undesired results. Always (as in &lt;STRONG&gt;ALWAYS&lt;/STRONG&gt;) use a comprehensive list of variables in the SELECT when doing a JOIN.&lt;/P&gt;
&lt;P&gt;In the opinion of senior SAS users (including me), SAS should not throw a WARNING here, but an ERROR, and refuse to accept such crap code. Like SQL in other systems does.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can do the "drop" by not including the unwanted variables in the SELECT, and calculate _ZNL like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;,coalesce(_znl,a.tgt_qty * b.cnv_rctr) as _znl&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 12 Apr 2022 10:48:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combine-steps/m-p/807341#M318293</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-04-12T10:48:39Z</dc:date>
    </item>
  </channel>
</rss>

