<?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 conditions macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Case-when-conditions-macro/m-p/780373#M248649</link>
    <description>works like a charm! Thanks! Now, looking to make it work inside a passthrough oracle query:)</description>
    <pubDate>Tue, 16 Nov 2021 09:54:02 GMT</pubDate>
    <dc:creator>mwilk</dc:creator>
    <dc:date>2021-11-16T09:54:02Z</dc:date>
    <item>
      <title>Case when conditions macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Case-when-conditions-macro/m-p/779313#M248169</link>
      <description>&lt;P&gt;Hi guys,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a problem with a macro (loop) that would create as many conditions as values I have in my column...&lt;/P&gt;&lt;P&gt;I have a code like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;case when UPPER(ORIG_NM) LIKE '%COINBASE%'&lt;BR /&gt;OR UPPER(BENEF_NM) LIKE '%COINBASE%'&lt;BR /&gt;OR UPPER(SCND_ORIG_NM) LIKE '%COINBASE%'&lt;BR /&gt;OR UPPER(SCND_BENEF_NM) LIKE'%COINBASE%'&lt;BR /&gt;OR UPPER(SEND_INSTN_NM) LIKE '%COINBASE%'&lt;BR /&gt;/* OR UPPER(ORIG_TO_BENEF_INSTR_TX) LIKE '%COINBASE%' */&lt;BR /&gt;OR UPPER(RCV_INSTN_NM) LIKE'%COINBASE%' then 'COINBASE'&lt;/P&gt;&lt;P&gt;when UPPER(ORIG_NM) LIKE '%BITFINEX%'&lt;BR /&gt;OR UPPER(BENEF_NM) LIKE '%BITFINEX%'&lt;BR /&gt;OR UPPER(SCND_ORIG_NM) LIKE '%BITFINEX%'&lt;BR /&gt;OR UPPER(SCND_BENEF_NM) LIKE'%BITFINEX%'&lt;BR /&gt;OR UPPER(SEND_INSTN_NM) LIKE '%BITFINEX%'&lt;BR /&gt;/* OR UPPER(ORIG_TO_BENEF_INSTR_TX) LIKE '%BITFINEX%' */&lt;BR /&gt;OR UPPER(RCV_INSTN_NM) LIKE'%BITFINEX%' then 'BITFINEX'&lt;/P&gt;&lt;P&gt;when UPPER(ORIG_NM) LIKE '%KRAKEN%'&lt;BR /&gt;OR UPPER(BENEF_NM) LIKE '%KRAKEN%'&lt;BR /&gt;OR UPPER(SCND_ORIG_NM) LIKE '%KRAKEN%'&lt;BR /&gt;OR UPPER(SCND_BENEF_NM) LIKE'%KRAKEN%'&lt;BR /&gt;OR UPPER(SEND_INSTN_NM) LIKE '%KRAKEN%'&lt;BR /&gt;/* OR UPPER(ORIG_TO_BENEF_INSTR_TX) LIKE '%KRAKEN%' */&lt;BR /&gt;OR UPPER(RCV_INSTN_NM) LIKE'%KRAKEN%' then 'KRAKEN'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;now, that 3 names (kraken, coinbase, bitfinex) are only 3 examples. I have a hundred of them and I would like not to repeat that section manually 100 times but do the loop that would add this section to my code as many times as many I have record in the table that the macro would pull the values from. Any ideas?&lt;/P&gt;</description>
      <pubDate>Tue, 09 Nov 2021 12:28:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Case-when-conditions-macro/m-p/779313#M248169</guid>
      <dc:creator>mwilk</dc:creator>
      <dc:date>2021-11-09T12:28:32Z</dc:date>
    </item>
    <item>
      <title>Re: Case when conditions macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Case-when-conditions-macro/m-p/779314#M248170</link>
      <description>&lt;P&gt;UNTESTED CODE&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro conditions(names=);
    %do i=1 %to %sysfunc(countw(&amp;amp;names));
        %let thisname=%scan(&amp;amp;names,i,%str( ));
        case when upper(orig_nm) like "%nrstr(%%)&amp;amp;thisname%nrstr(%%)"
        or upper(benef_nm) like "%nrstr(%%)&amp;amp;thisname%nrstr(%%)"
        or  /* I'm lazy, you type the rest */
        then "&amp;amp;thisname"
     %end;
%mend;

proc sql;
      /* Some appropriate SQL code */
      %conditions(names=COINBASE BITFINEX KRAKEN BUFFALO SYRACUSE ROCHESTER UTICA ALBANY)
      /* more appropriate SQL code */
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 09 Nov 2021 12:38:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Case-when-conditions-macro/m-p/779314#M248170</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-11-09T12:38:15Z</dc:date>
    </item>
    <item>
      <title>Re: Case when conditions macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Case-when-conditions-macro/m-p/779324#M248178</link>
      <description>&lt;P&gt;Here is a macro that can iterate both the fields and the texts:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro case_cond(texts,                                             
  fields=ORIG_NM BENEF_NM SCND_ORIG_NM SCND_BENEF_NM SEND_INSTN_NM);
  %local i j like_str text;                                         
  %let texts=%upcase(&amp;amp;texts);                                       
  %do i=1 %to %sysfunc(countw(&amp;amp;texts));                             
    %let text=%scan(&amp;amp;texts,&amp;amp;i);                                     
     %let like_str=%unquote(%nrstr(%'%%)&amp;amp;text%nrstr(%%%'));         
       when upper(%scan(&amp;amp;fields,1)) like &amp;amp;like_str                 
    %do j=2 %to %sysfunc(countw(&amp;amp;fields));                          
      or upper(%scan(&amp;amp;fields,&amp;amp;j)) like &amp;amp;like_str                    
      %end;                                                         
    then %str(%'&amp;amp;text%')                                            
    %end;                                                           
%mend;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So you would generate the code you supplied like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%case_cond(COINBASE BITFINEX KRAKEN)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And if you also wanted the lines you commented out, you can do it like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%case_cond(COINBASE BITFINEX KRAKEN,
           fields=ORIG_NM BENEF_NM SCND_ORIG_NM SCND_BENEF_NM &lt;SPAN&gt;ORIG_TO_BENEF_INSTR_TX&lt;/SPAN&gt; SEND_INSTN_NM)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The macro can be made a bit simpler if you use the CONTAINS or ? condition instead of LIKE (? "TEST" is the same as LIKE '%TEST%'):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro case_cond(texts,                                             
  fields=ORIG_NM BENEF_NM SCND_ORIG_NM SCND_BENEF_NM SEND_INSTN_NM);
  %local i j text;                                                  
  %let texts=%upcase(&amp;amp;texts);                                       
  %do i=1 %to %sysfunc(countw(&amp;amp;texts));                             
    %let text="%scan(&amp;amp;texts,&amp;amp;i)";                                   
     when upper(%scan(&amp;amp;fields,1)) ? &amp;amp;text                       
    %do j=2 %to %sysfunc(countw(&amp;amp;fields));                          
       or upper(%scan(&amp;amp;fields,&amp;amp;j)) ? &amp;amp;text                          
      %end;                                                         
    then &amp;amp;text                                                      
    %end;                                                           
%mend;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit note: I took the CASE keyword out of the macro (I had misplaced it, any way), so now the macro should be used like e.g.:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
  select name,
     case %case_cond(a b c)
     else 'NOTHING'
    end as test
  from x;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Nov 2021 13:46:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Case-when-conditions-macro/m-p/779324#M248178</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2021-11-09T13:46:20Z</dc:date>
    </item>
    <item>
      <title>Re: Case when conditions macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Case-when-conditions-macro/m-p/779326#M248180</link>
      <description>&lt;P&gt;Do you want precedence as defined by the order of the comparisons?&lt;/P&gt;
&lt;P&gt;What if orig_nm = "coinbase" and benef_nm = "bitfinex" and scnd_orig_nm = "kraken"?&lt;/P&gt;</description>
      <pubDate>Tue, 09 Nov 2021 13:17:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Case-when-conditions-macro/m-p/779326#M248180</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-11-09T13:17:58Z</dc:date>
    </item>
    <item>
      <title>Re: Case when conditions macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Case-when-conditions-macro/m-p/779368#M248194</link>
      <description>&lt;P&gt;I'm not worried about that. That should not happen. Thanks&lt;/P&gt;</description>
      <pubDate>Tue, 09 Nov 2021 16:20:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Case-when-conditions-macro/m-p/779368#M248194</guid>
      <dc:creator>mwilk</dc:creator>
      <dc:date>2021-11-09T16:20:35Z</dc:date>
    </item>
    <item>
      <title>Re: Case when conditions macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Case-when-conditions-macro/m-p/779369#M248195</link>
      <description>Thank you! I will try to make a use of this.</description>
      <pubDate>Tue, 09 Nov 2021 16:21:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Case-when-conditions-macro/m-p/779369#M248195</guid>
      <dc:creator>mwilk</dc:creator>
      <dc:date>2021-11-09T16:21:04Z</dc:date>
    </item>
    <item>
      <title>Re: Case when conditions macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Case-when-conditions-macro/m-p/779370#M248196</link>
      <description>Unfortunately that doesn't work:(</description>
      <pubDate>Tue, 09 Nov 2021 16:33:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Case-when-conditions-macro/m-p/779370#M248196</guid>
      <dc:creator>mwilk</dc:creator>
      <dc:date>2021-11-09T16:33:13Z</dc:date>
    </item>
    <item>
      <title>Re: Case when conditions macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Case-when-conditions-macro/m-p/779371#M248197</link>
      <description>ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric&lt;BR /&gt;operand is required. The condition was: i&lt;BR /&gt;ERROR: Argument 2 to macro function %SCAN is not a number.&lt;BR /&gt;ERROR: The macro CONDITIONS will stop executing.&lt;BR /&gt;</description>
      <pubDate>Tue, 09 Nov 2021 16:34:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Case-when-conditions-macro/m-p/779371#M248197</guid>
      <dc:creator>mwilk</dc:creator>
      <dc:date>2021-11-09T16:34:41Z</dc:date>
    </item>
    <item>
      <title>Re: Case when conditions macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Case-when-conditions-macro/m-p/779375#M248198</link>
      <description>Unfrtunately I can't get it working but will spend some time on it tomorrow. This is not an easy task I know &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;&lt;BR /&gt;311 proc sql;&lt;BR /&gt;312 select *,&lt;BR /&gt;313 case %case_cond(COINBASE BITFINEX KRAKEN)&lt;BR /&gt;NOTE 137-205: Line generated by the invoked macro "CASE_COND".&lt;BR /&gt;16 then '&amp;amp;text'&lt;BR /&gt;-&lt;BR /&gt;22&lt;BR /&gt;ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string,&lt;BR /&gt;a numeric constant, a datetime constant, a missing value, (, +, -, BTRIM,&lt;BR /&gt;CALCULATED, CASE, EXISTS, INPUT, NOT, PUT, SELECT, SUBSTRING, TRANSLATE, USER, ^,&lt;BR /&gt;</description>
      <pubDate>Tue, 09 Nov 2021 16:42:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Case-when-conditions-macro/m-p/779375#M248198</guid>
      <dc:creator>mwilk</dc:creator>
      <dc:date>2021-11-09T16:42:49Z</dc:date>
    </item>
    <item>
      <title>Re: Case when conditions macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Case-when-conditions-macro/m-p/779382#M248202</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/405969"&gt;@mwilk&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I'm not worried about that. That should not happen. Thanks&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;"Should not" is not "can't". Code a safeguard against that.&lt;/P&gt;</description>
      <pubDate>Tue, 09 Nov 2021 17:35:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Case-when-conditions-macro/m-p/779382#M248202</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-11-09T17:35:08Z</dc:date>
    </item>
    <item>
      <title>Re: Case when conditions macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Case-when-conditions-macro/m-p/779517#M248273</link>
      <description>&lt;P&gt;You're right, there is some macro quoting problems in the first macro (I only tested the second version).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try this instead:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro case_cond(texts,                                             
  fields=ORIG_NM BENEF_NM SCND_ORIG_NM SCND_BENEF_NM SEND_INSTN_NM);
  %local i j like_str text;                                         
  %let texts=%upcase(&amp;amp;texts);                                       
  %do i=1 %to %sysfunc(countw(&amp;amp;texts));                             
    %let text=%scan(&amp;amp;texts,&amp;amp;i);                                     
     %let like_str=%unquote(%nrstr(%'%%)&amp;amp;text%nrstr(%%%'));         
       when upper(%scan(&amp;amp;fields,1)) like &amp;amp;like_str                  
    %do j=2 %to %sysfunc(countw(&amp;amp;fields));                          
      or upper(%scan(&amp;amp;fields,&amp;amp;j)) like &amp;amp;like_str                    
      %end;                                                         
    then %sysfunc(quote(&amp;amp;text,%str(%')))                            
    %put _local_;                                                   
    %end;                                                           
%mend;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;(I used the %sysfunc(quote()) instead of&amp;nbsp;%str(%'&amp;amp;text%'))&lt;/P&gt;</description>
      <pubDate>Wed, 10 Nov 2021 08:20:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Case-when-conditions-macro/m-p/779517#M248273</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2021-11-10T08:20:59Z</dc:date>
    </item>
    <item>
      <title>Re: Case when conditions macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Case-when-conditions-macro/m-p/780373#M248649</link>
      <description>works like a charm! Thanks! Now, looking to make it work inside a passthrough oracle query:)</description>
      <pubDate>Tue, 16 Nov 2021 09:54:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Case-when-conditions-macro/m-p/780373#M248649</guid>
      <dc:creator>mwilk</dc:creator>
      <dc:date>2021-11-16T09:54:02Z</dc:date>
    </item>
    <item>
      <title>Re: Case when conditions macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Case-when-conditions-macro/m-p/780382#M248655</link>
      <description>&lt;P&gt;Since you have been extremely helpful I have one more question. I try to use very similar macro for simple WHERE clause and I got:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;%macro filter_cond(texts,&lt;BR /&gt;fields=ORIG_NM BENEF_NM SCND_ORIG_NM SCND_BENEF_NM);&lt;BR /&gt;%local i j like_str text;&lt;BR /&gt;%let texts=%upcase(&amp;amp;texts);&lt;BR /&gt;%do i=1 %to %sysfunc(countw(&amp;amp;texts));&lt;BR /&gt;%let text=%scan(&amp;amp;texts,&amp;amp;i);&lt;BR /&gt;%let like_str=%unquote(%nrstr(%'%%)&amp;amp;text%nrstr(%%%'));&lt;BR /&gt;upper(%scan(&amp;amp;fields,1)) like &amp;amp;like_str or&lt;BR /&gt;%do j=2 %to %sysfunc(countw(&amp;amp;fields));&lt;BR /&gt;upper(%scan(&amp;amp;fields,&amp;amp;j)) like &amp;amp;like_str or&lt;BR /&gt;%end;&lt;BR /&gt;%put _local_;&lt;BR /&gt;%end;&lt;BR /&gt;%mend;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The problem is the last iteration still puts "or" after last string search and query doesn't work because of that.&lt;/P&gt;&lt;P&gt;Would you know how to remove last "or"? Tried something like -1 to each iteration but that applies to more than doesn't work since we have a loop in the loop and we need to remove "or" from the very last line generated.&lt;/P&gt;</description>
      <pubDate>Tue, 16 Nov 2021 10:43:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Case-when-conditions-macro/m-p/780382#M248655</guid>
      <dc:creator>mwilk</dc:creator>
      <dc:date>2021-11-16T10:43:29Z</dc:date>
    </item>
    <item>
      <title>Re: Case when conditions macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Case-when-conditions-macro/m-p/780383#M248656</link>
      <description>proc sql noprint;&lt;BR /&gt;create table test as&lt;BR /&gt;select *&lt;BR /&gt;from db&lt;BR /&gt;where %filter_cond(&amp;amp;platforms)&lt;BR /&gt;;&lt;BR /&gt;quit;</description>
      <pubDate>Tue, 16 Nov 2021 10:44:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Case-when-conditions-macro/m-p/780383#M248656</guid>
      <dc:creator>mwilk</dc:creator>
      <dc:date>2021-11-16T10:44:27Z</dc:date>
    </item>
    <item>
      <title>Re: Case when conditions macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Case-when-conditions-macro/m-p/780385#M248657</link>
      <description>&lt;P&gt;Make the "or" conditional:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%do j=2 %to %sysfunc(countw(&amp;amp;fields));
  upper(%scan(&amp;amp;fields,&amp;amp;j)) like &amp;amp;like_str 
  %if &amp;amp;j. ne %sysfunc(countw(&amp;amp;fields) then or;
%end;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 16 Nov 2021 10:53:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Case-when-conditions-macro/m-p/780385#M248657</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-11-16T10:53:16Z</dc:date>
    </item>
    <item>
      <title>Re: Case when conditions macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Case-when-conditions-macro/m-p/780389#M248658</link>
      <description>This will remove "or" for each main loop iteration which won't work.&lt;BR /&gt;&lt;BR /&gt;I have came up with something that works but probably is not well optimized:&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;%macro filter_cond(texts,&lt;BR /&gt;fields=ORIG_NM BENEF_NM SCND_ORIG_NM SCND_BENEF_NM);&lt;BR /&gt;%local i j like_str text;&lt;BR /&gt;%let texts=%upcase(&amp;amp;texts);&lt;BR /&gt;%do i=1 %to 1;&lt;BR /&gt;%let text=%scan(&amp;amp;texts,&amp;amp;i);&lt;BR /&gt;%let like_str=%unquote(%nrstr(%'%%)&amp;amp;text%nrstr(%%%'));&lt;BR /&gt;upper(%scan(&amp;amp;fields,1)) like &amp;amp;like_str&lt;BR /&gt;%do j=2 %to %sysfunc(countw(&amp;amp;fields));&lt;BR /&gt;or upper(%scan(&amp;amp;fields,&amp;amp;j)) like &amp;amp;like_str&lt;BR /&gt;%end;&lt;BR /&gt;%put _local_;&lt;BR /&gt;%end;&lt;BR /&gt;%do i=2 %to %sysfunc(countw(&amp;amp;texts));&lt;BR /&gt;%let text=%scan(&amp;amp;texts,&amp;amp;i);&lt;BR /&gt;%let like_str=%unquote(%nrstr(%'%%)&amp;amp;text%nrstr(%%%'));&lt;BR /&gt;or upper(%scan(&amp;amp;fields,1)) like &amp;amp;like_str&lt;BR /&gt;%do j=2 %to %sysfunc(countw(&amp;amp;fields));&lt;BR /&gt;or upper(%scan(&amp;amp;fields,&amp;amp;j)) like &amp;amp;like_str&lt;BR /&gt;%end;&lt;BR /&gt;%put _local_;&lt;BR /&gt;%end;&lt;BR /&gt;%mend;</description>
      <pubDate>Tue, 16 Nov 2021 11:24:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Case-when-conditions-macro/m-p/780389#M248658</guid>
      <dc:creator>mwilk</dc:creator>
      <dc:date>2021-11-16T11:24:20Z</dc:date>
    </item>
    <item>
      <title>Re: Case when conditions macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Case-when-conditions-macro/m-p/783933#M250085</link>
      <description>&lt;P&gt;Who possibly can help me to modify this macro, so that once it finds the required text in particular field, instead of putting this text as a value, it will put a value from different variable from that record. Something like that in macro:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Case when benef_nm LIKE '%KRAKEN%' then benef_acct_id&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;when orig_nm LIKE '%KRAKEN%' then orig_acct_id&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;when&amp;nbsp;send_nm LIKE '%BINANCE%' then send_acct_id&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Before, it was like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Case when benef_nm LIKE '%KRAKEN%' then 'KRAKEN'&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;when orig_nm LIKE '%KRAKEN%' then 'KRAKEN'&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;when&amp;nbsp;send_nm LIKE '%BINANCE%' then 'BINANCE'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;anyone knows how to modify this? I'm struggling here....&lt;/P&gt;</description>
      <pubDate>Fri, 03 Dec 2021 14:21:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Case-when-conditions-macro/m-p/783933#M250085</guid>
      <dc:creator>mwilk</dc:creator>
      <dc:date>2021-12-03T14:21:33Z</dc:date>
    </item>
    <item>
      <title>Re: Case when conditions macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Case-when-conditions-macro/m-p/784294#M250260</link>
      <description>&lt;P&gt;so noone can help on this?&lt;/P&gt;</description>
      <pubDate>Mon, 06 Dec 2021 12:30:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Case-when-conditions-macro/m-p/784294#M250260</guid>
      <dc:creator>mwilk</dc:creator>
      <dc:date>2021-12-06T12:30:45Z</dc:date>
    </item>
    <item>
      <title>Re: Case when conditions macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Case-when-conditions-macro/m-p/784364#M250299</link>
      <description>&lt;P&gt;Do you want to start a new thread for the new question?&lt;/P&gt;
&lt;P&gt;In general if the code generation is too complex you are better off using a DATA step to generate the code instead of macro code.&amp;nbsp; You will be able to debug the code much easier.&lt;/P&gt;</description>
      <pubDate>Mon, 06 Dec 2021 19:01:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Case-when-conditions-macro/m-p/784364#M250299</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-12-06T19:01:57Z</dc:date>
    </item>
    <item>
      <title>Re: Case when conditions macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Case-when-conditions-macro/m-p/784490#M250362</link>
      <description>Actually macro works well for the of the problem I had. This one is very similar but instead of returning the value when condition met I need it to return value from different variable. Macro seems to be the answer for such "case when" with multiple conditions. Can't think of the data step to resolve this. Number of "whens" is dynamic and comes from the external file. So, yes, macro seems to be the answer. The problem is I'm struggling to get it to work! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Tue, 07 Dec 2021 09:08:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Case-when-conditions-macro/m-p/784490#M250362</guid>
      <dc:creator>mwilk</dc:creator>
      <dc:date>2021-12-07T09:08:14Z</dc:date>
    </item>
  </channel>
</rss>

