<?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: Case when using macro variables. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Case-when-using-macro-variables/m-p/612323#M178650</link>
    <description>&lt;P&gt;Keep your lookup values in a dataset, create a format from it, and use it in a put() function:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data lookup;
fmtname = "lookup";
type = 'C';
if _n_ = 1
then do;
  start = 'Other';
  label = '***';
  hlo = 'O';
  output;
end;
input start $ label $;
hlo = '';
output;
datalines;
5801 EUR
5701 EUR
3009 PLN
;

proc format cntlin=lookup;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;then use&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;case
  when put(unit,$lookup.) = '***'
  then currency
  else put(unit,$lookup.)
end as newvar&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 17 Dec 2019 07:45:36 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2019-12-17T07:45:36Z</dc:date>
    <item>
      <title>Case when using macro variables.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Case-when-using-macro-variables/m-p/612321#M178648</link>
      <description />
      <pubDate>Thu, 19 Dec 2019 09:30:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Case-when-using-macro-variables/m-p/612321#M178648</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2019-12-19T09:30:15Z</dc:date>
    </item>
    <item>
      <title>Re: Case when using macro variables.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Case-when-using-macro-variables/m-p/612323#M178650</link>
      <description>&lt;P&gt;Keep your lookup values in a dataset, create a format from it, and use it in a put() function:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data lookup;
fmtname = "lookup";
type = 'C';
if _n_ = 1
then do;
  start = 'Other';
  label = '***';
  hlo = 'O';
  output;
end;
input start $ label $;
hlo = '';
output;
datalines;
5801 EUR
5701 EUR
3009 PLN
;

proc format cntlin=lookup;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;then use&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;case
  when put(unit,$lookup.) = '***'
  then currency
  else put(unit,$lookup.)
end as newvar&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 17 Dec 2019 07:45:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Case-when-using-macro-variables/m-p/612323#M178650</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-12-17T07:45:36Z</dc:date>
    </item>
    <item>
      <title>Re: Case when using macro variables.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Case-when-using-macro-variables/m-p/612326#M178651</link>
      <description>Thanks. Is there a way that we can tackle it using macro variables as&lt;BR /&gt;mentioned in the initial post?&lt;BR /&gt;</description>
      <pubDate>Tue, 17 Dec 2019 07:57:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Case-when-using-macro-variables/m-p/612326#M178651</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2019-12-17T07:57:49Z</dc:date>
    </item>
    <item>
      <title>Re: Case when using macro variables.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Case-when-using-macro-variables/m-p/612328#M178652</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292396"&gt;@David_Billa&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Thanks. Is there a way that we can tackle it using macro variables as&lt;BR /&gt;mentioned in the initial post?&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Yes, but it's inefficient, so I won't waste time with it.&lt;/P&gt;
&lt;P&gt;Lookup &lt;STRONG&gt;DATA&lt;/STRONG&gt; belongs in &lt;STRONG&gt;DATA&lt;/STRONG&gt;SETS, and can easily be processed from there with &lt;EM&gt;static code&lt;/EM&gt; which needs no macro processing.&lt;/P&gt;</description>
      <pubDate>Tue, 17 Dec 2019 08:05:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Case-when-using-macro-variables/m-p/612328#M178652</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-12-17T08:05:06Z</dc:date>
    </item>
    <item>
      <title>Re: Case when using macro variables.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Case-when-using-macro-variables/m-p/612359#M178673</link>
      <description>&lt;P&gt;One solution is to create a macro function which creates the cases:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let Currencies=5801_EUR 5701_EUR 3009_PLN;
%macro CaseStr(Currencies);
  %local i w;
  %do i=1 %to %sysfunc(countw(&amp;amp;Currencies,%str( )));
    %let w=%scan(&amp;amp;Currencies,&amp;amp;i,%str( ));
    %do; when UNIT="%scan(&amp;amp;w,1,_)" then "%scan(&amp;amp;w,2,_)" %end;
    %end;
%mend;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then you can use that in the case statement:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Case
  %CaseStr(&amp;amp;Currencies)
  Else CURRENCY
end&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or you can use the values directly, instead of the CURRENCIES macro variable, if you only refer to them once:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;case
  %CaseStr(5801_EUR 5701_EUR 3009_PLN)
  else CURRENCY
end&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 17 Dec 2019 11:42:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Case-when-using-macro-variables/m-p/612359#M178673</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2019-12-17T11:42:45Z</dc:date>
    </item>
  </channel>
</rss>

