<?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: Macro Parameter in SELECT CASE in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-Parameter-in-SELECT-CASE/m-p/315396#M270844</link>
    <description>&lt;P&gt;Thankyou guys... A great help in this case..&lt;/P&gt;</description>
    <pubDate>Wed, 30 Nov 2016 03:29:41 GMT</pubDate>
    <dc:creator>aj34321</dc:creator>
    <dc:date>2016-11-30T03:29:41Z</dc:date>
    <item>
      <title>Macro Parameter in SELECT CASE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Parameter-in-SELECT-CASE/m-p/315063#M270839</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Im trying to use a macro passed parameter in Proc SQL Case as below.&amp;nbsp;Something is wrong in this as the output is not as expected.&lt;/P&gt;
&lt;P&gt;Request someone to guide me if i can use this approach?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro InsertTable(pSourceTable=, pLoadMethod=, pDataTransferID=);&lt;BR /&gt; proc sql;&lt;BR /&gt; insert into &amp;lt;TableName&amp;gt; &lt;BR /&gt; (&lt;BR /&gt; Column1,&lt;BR /&gt; Column2,&lt;BR /&gt; Column3,&lt;BR /&gt; Column4&lt;BR /&gt; ) &lt;BR /&gt; select &lt;BR /&gt; Column1,&lt;BR /&gt; Column2,&lt;BR /&gt; case &amp;amp;LoadMethod.&lt;BR /&gt; when 'D' then Column3&lt;BR /&gt; when 'F' then &amp;amp;pDataTransferID.&lt;BR /&gt; end as Column3,&lt;/P&gt;
&lt;P&gt;case &amp;amp;LoadMethod.&lt;BR /&gt; when 'D' then Column4&lt;BR /&gt; when 'F' then 'I'&lt;BR /&gt; end as Column4&lt;BR /&gt; from &amp;amp;pSourceTable.;&lt;BR /&gt; quit;&lt;BR /&gt;%mend InsertTable;&lt;/P&gt;
&lt;P&gt;%InsertTable(pSourceTable=SourceTable, pLoadMethod='D', pDataTransferID=1);&lt;BR /&gt;%InsertTable(pSourceTable=SourceTable, pLoadMethod='F', pDataTransferID=1);&lt;/P&gt;</description>
      <pubDate>Tue, 29 Nov 2016 02:28:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Parameter-in-SELECT-CASE/m-p/315063#M270839</guid>
      <dc:creator>aj34321</dc:creator>
      <dc:date>2016-11-29T02:28:23Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Parameter in SELECT CASE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Parameter-in-SELECT-CASE/m-p/315067#M270840</link>
      <description>&lt;P&gt;The parameter &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;LoadMethod &lt;/STRONG&gt;&lt;FONT color="#000000"&gt;should be a column name rather than value. &lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF0000"&gt;&lt;FONT color="#000000"&gt;Anything after the case should be a column name and not the value. &lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF0000"&gt;&lt;FONT color="#000000"&gt;could you please try replacing the 'D' with column name.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro InsertTable(pSourceTable=, pLoadMethod=, pDataTransferID=);&lt;BR /&gt; proc sql;&lt;BR /&gt; insert into &amp;lt;TableName&amp;gt; &lt;BR /&gt; (&lt;BR /&gt; Column1,&lt;BR /&gt; Column2,&lt;BR /&gt; Column3,&lt;BR /&gt; Column4&lt;BR /&gt; ) &lt;BR /&gt; select &lt;BR /&gt; Column1,&lt;BR /&gt; Column2,&lt;BR /&gt; case &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;&amp;amp;LoadMethod.&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt; when 'D' then Column3&lt;BR /&gt; when 'F' then &amp;amp;pDataTransferID.&lt;BR /&gt; end as Column3,&lt;/P&gt;
&lt;P&gt;case &lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;&amp;amp;LoadMethod.&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt; when 'D' then Column4&lt;BR /&gt; when 'F' then 'I'&lt;BR /&gt; end as Column4&lt;BR /&gt; from &amp;amp;pSourceTable.;&lt;BR /&gt; quit;&lt;BR /&gt;%mend InsertTable;&lt;/P&gt;
&lt;P&gt;%InsertTable(pSourceTable=SourceTable, pLoadMethod='D', pDataTransferID=1);&lt;/P&gt;</description>
      <pubDate>Tue, 29 Nov 2016 03:15:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Parameter-in-SELECT-CASE/m-p/315067#M270840</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2016-11-29T03:15:22Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Parameter in SELECT CASE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Parameter-in-SELECT-CASE/m-p/315068#M270841</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro InsertTable(pSourceTable=, pLoadMethod=, pDataTransferID=);
proc sql;
insert into &amp;lt;TableName&amp;gt; 
(
Column1,
Column2,
Column3,
Column4
) 
select 
Column1,
Column2,
case 
when &amp;amp;pLoadMethod ='D' then Column3
when &amp;amp;pLoadMethod ='F' then &amp;amp;pDataTransferID.
end as Column3,
case 
when &amp;amp;pLoadMethod ='D' then Column4
when &amp;amp;pLoadMethod ='F' then 'I'
end as Column4
from &amp;amp;pSourceTable.;
quit;
%mend InsertTable;
%InsertTable(pSourceTable=SourceTable, pLoadMethod='D', pDataTransferID=1);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I think you are looking for the code that I have written above.&lt;/P&gt;&lt;P&gt;I see problem in case statement. After Case keyword there should be variable name. I do not find any macro variable as LoadMethod in the given code. Suggest you to try the code with actual variable first. Once code run fine then replace the variables with macro variable.&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;&lt;P&gt;&lt;SPAN&gt;case &amp;amp;LoadMethod.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;when 'D' then Column3&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;when 'F' then &amp;amp;pDataTransferID.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;end as Column3,&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Nov 2016 03:24:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Parameter-in-SELECT-CASE/m-p/315068#M270841</guid>
      <dc:creator>RahulG</dc:creator>
      <dc:date>2016-11-29T03:24:38Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Parameter in SELECT CASE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Parameter-in-SELECT-CASE/m-p/315084#M270842</link>
      <description>&lt;P&gt;I'm not sure if it will&amp;nbsp;return the intended result for you, but having a string in the CASE portion is valid syntax as such.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  infile datalines dsd;
  input t1 $ t2 $;
  datalines;
X,Y
X,Y
X,Y
;
run;

%let type=A;
proc sql feedback;
  create table want as
    select
    have.*,
    case "&amp;amp;type"
      when "A" then t1
      else t2
      end as test1,
    case "&amp;amp;type"
      when "B" then t1
      else t2
      end as test2
  from have
  ;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/6090i6DF343AA502B6CBC/image-size/original?v=v2&amp;amp;px=-1" border="0" alt="Capture.PNG" title="Capture.PNG" /&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Nov 2016 04:21:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Parameter-in-SELECT-CASE/m-p/315084#M270842</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2016-11-29T04:21:28Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Parameter in SELECT CASE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Parameter-in-SELECT-CASE/m-p/315089#M270843</link>
      <description>&lt;P&gt;Your macro variable is PLoadMethod -&amp;gt; missing the p.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Nov 2016 04:42:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Parameter-in-SELECT-CASE/m-p/315089#M270843</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-11-29T04:42:32Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Parameter in SELECT CASE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Parameter-in-SELECT-CASE/m-p/315396#M270844</link>
      <description>&lt;P&gt;Thankyou guys... A great help in this case..&lt;/P&gt;</description>
      <pubDate>Wed, 30 Nov 2016 03:29:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Parameter-in-SELECT-CASE/m-p/315396#M270844</guid>
      <dc:creator>aj34321</dc:creator>
      <dc:date>2016-11-30T03:29:41Z</dc:date>
    </item>
  </channel>
</rss>

