<?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: Conditional %IF %THEN processing as a macro parameter in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Conditional-IF-THEN-processing-as-a-macro-parameter/m-p/958146#M373983</link>
    <description>&lt;P&gt;I cannot understand what you are trying to do.&lt;/P&gt;
&lt;P&gt;This code makes no sense:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; %if DV LT 6 %then %do; 3 %end; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The letter D comes after the digit 6 so you are going to always generate 3 with that code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to test the value of a dataset variable you need to use SAS code, not macro code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please show the actual SAS code you are trying to use the macro processor to generate.&amp;nbsp; Then perhaps we can help you generate it (if any code generation is needed).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 04 Feb 2025 02:47:04 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2025-02-04T02:47:04Z</dc:date>
    <item>
      <title>Conditional %IF %THEN processing as a macro parameter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-IF-THEN-processing-as-a-macro-parameter/m-p/958135#M373979</link>
      <description>&lt;P&gt;I am looking to modify macro parameters using %IF %THEN conditional macro language.&amp;nbsp; Unfortunately, conditional macro language cannot be used as part of another macro's parameter specification.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This community has been an invaluable resource.&amp;nbsp; Can I ask for ideas how to proceed?&amp;nbsp; I know I can do CASE WHEN and condition it on variable DV that way; however, the lists can be long and differ by one number most of the time.&amp;nbsp; I'd hate to type them out twice and open the door for errors in the future edits.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the example below, both Pt 1 and 2 should get value 1=Yes while both Pt 3 and 4should get 0=No.&lt;/P&gt;
&lt;P&gt;- &lt;U&gt;Pt&lt;/U&gt;=1 has both &lt;U&gt;Proc&lt;/U&gt;=1 and &lt;U&gt;Proc&lt;/U&gt;=2.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;- &lt;U&gt;Pt&lt;/U&gt;=2 has &lt;U&gt;Proc&lt;/U&gt;=1 and (&lt;U&gt;Proc&lt;/U&gt;=3 AND &lt;U&gt;DV&lt;/U&gt;&amp;lt;6)&lt;/P&gt;
&lt;P&gt;- &lt;U&gt;Pt&lt;/U&gt;=3 has &lt;U&gt;Proc&lt;/U&gt;=1 and &lt;U&gt;Proc&lt;/U&gt;=3 but &lt;U&gt;DV&lt;/U&gt;&amp;gt;6.&lt;/P&gt;
&lt;P&gt;- Pt=4 has &lt;U&gt;Proc&lt;/U&gt;=1 but no &lt;U&gt;Proc&lt;/U&gt;=2 OR &lt;U&gt;Proc&lt;/U&gt;=3 even though &lt;U&gt;DV&lt;/U&gt;&amp;lt;6.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data x;&lt;BR /&gt;input Pt Proc DataVrsn @@;&lt;BR /&gt;cards;&lt;BR /&gt;1 1 6 1 2 6 1 4 6 &lt;BR /&gt;2 1 5 2 3 5 2 5 5 &lt;BR /&gt;3 1 7 3 3 7 3 5 7 &lt;BR /&gt;4 1 4 4 4 4 4 5 4 &lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;
%macro CC(PL1,PL2,PL3,PL4);
	max(Proc IN (&amp;amp;PL1)) AND max(Proc IN (&amp;amp;PL2))
  %if &amp;amp;PL3&amp;gt;0 %then %do; AND max(Proc IN (&amp;amp;PL3)) %end;
  %if &amp;amp;PL4&amp;gt;0 %then %do; AND max(Proc IN (&amp;amp;PL4)) %end;
%mend CC;

options mPrint mLogic SymbolGen;
proc sql;
	select Pt,
		%CC(1,2 %if DV LT 6 %then %do; 3 %end; )	as CC12_3
	from x
	group by Pt
;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 03 Feb 2025 23:25:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-IF-THEN-processing-as-a-macro-parameter/m-p/958135#M373979</guid>
      <dc:creator>Haris</dc:creator>
      <dc:date>2025-02-03T23:25:52Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional %IF %THEN processing as a macro parameter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-IF-THEN-processing-as-a-macro-parameter/m-p/958136#M373980</link>
      <description>&lt;P&gt;Sorry, I can't insert line-breaks for some reason.&amp;nbsp; The DATA step ignores them &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 03 Feb 2025 23:24:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-IF-THEN-processing-as-a-macro-parameter/m-p/958136#M373980</guid>
      <dc:creator>Haris</dc:creator>
      <dc:date>2025-02-03T23:24:37Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional %IF %THEN processing as a macro parameter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-IF-THEN-processing-as-a-macro-parameter/m-p/958146#M373983</link>
      <description>&lt;P&gt;I cannot understand what you are trying to do.&lt;/P&gt;
&lt;P&gt;This code makes no sense:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; %if DV LT 6 %then %do; 3 %end; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The letter D comes after the digit 6 so you are going to always generate 3 with that code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to test the value of a dataset variable you need to use SAS code, not macro code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please show the actual SAS code you are trying to use the macro processor to generate.&amp;nbsp; Then perhaps we can help you generate it (if any code generation is needed).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Feb 2025 02:47:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-IF-THEN-processing-as-a-macro-parameter/m-p/958146#M373983</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-02-04T02:47:04Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional %IF %THEN processing as a macro parameter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-IF-THEN-processing-as-a-macro-parameter/m-p/958150#M373984</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13995"&gt;@Haris&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Sorry, I can't insert line-breaks for some reason.&amp;nbsp; The DATA step ignores them &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Always click on the Insert Code (or Insert SAS Code) icon to edit when you are modifying the number of lines in the inserted text.&lt;/P&gt;</description>
      <pubDate>Tue, 04 Feb 2025 03:07:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-IF-THEN-processing-as-a-macro-parameter/m-p/958150#M373984</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-02-04T03:07:43Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional %IF %THEN processing as a macro parameter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-IF-THEN-processing-as-a-macro-parameter/m-p/958152#M373986</link>
      <description>&lt;P&gt;Are you just trying to do this?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data x;
  input Pt Proc DV ;
cards;
1 1 6
1 2 6
1 4 6
2 1 5
2 3 5
2 5 5
3 1 7
3 3 7
3 5 7
4 1 4
4 4 4
4 5 4
;

proc sql ;
create table want as
select pt
     , (max(pt=1)
    or max(pt=2)
    or max(pt=3 and DV &amp;lt; 6)
       ) as flag
from x
group by Pt
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Feb 2025 03:24:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-IF-THEN-processing-as-a-macro-parameter/m-p/958152#M373986</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-02-04T03:24:37Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional %IF %THEN processing as a macro parameter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-IF-THEN-processing-as-a-macro-parameter/m-p/958248#M374006</link>
      <description>&lt;P&gt;Thanks for your attention and input, Tom.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I realize now that my post contained too much unnecessary detail irrelevant to the question I am asking.&amp;nbsp; The fact that I renamed variable DV to DataVrsn when trying to fix the line-break issues did not help matters at all.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks, for straightening up the fact that you CANNOT use variable values in the %IF %THEN conditional processing.&amp;nbsp; Not the way I am trying to go about it anyway.&amp;nbsp; But, in the end, that's what I am trying to accomplish: change a list that is evaluated by the &amp;lt;&lt;U&gt;VarName&lt;/U&gt;&amp;gt; IN (Value1, ..., ValueN) statement conditional on the value of the &lt;U&gt;DataVrsn&lt;/U&gt; variable.&amp;nbsp; Hope this code will illustrate it better: what I need is variable &lt;U&gt;CC123&lt;/U&gt;.&amp;nbsp; What I am hoping to do is to eliminate redundant typing of both redundant THEN and ELSE conditions and replace them with a conditional processing that adds a value to the list.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro runSQL();
proc sql;
	select Pt, Proc, DataVrsn,
	   case when DataVrsn&amp;lt;6 then max(Proc IN (1)) AND max(Proc IN (2  ))
	   						else max(Proc IN (1)) AND max(Proc IN (2 3)) end 		AS CC123,
		max(Proc IN (1)) AND max(Proc IN (2 %if DataVrsn LT 6 %then %do; 3 %end; )) AS ConditionalCC123
	from x
	group by Pt
	order by Pt, Proc
;
quit;
%mend runSQL;

%runSQL;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 04 Feb 2025 18:07:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-IF-THEN-processing-as-a-macro-parameter/m-p/958248#M374006</guid>
      <dc:creator>Haris</dc:creator>
      <dc:date>2025-02-04T18:07:26Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional %IF %THEN processing as a macro parameter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-IF-THEN-processing-as-a-macro-parameter/m-p/958269#M374014</link>
      <description>&lt;P&gt;Why? What will it gain you?&lt;/P&gt;
&lt;P&gt;Not sure I see any&amp;nbsp;advantage in making the code harder to understand.&lt;/P&gt;</description>
      <pubDate>Tue, 04 Feb 2025 19:43:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-IF-THEN-processing-as-a-macro-parameter/m-p/958269#M374014</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-02-04T19:43:37Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional %IF %THEN processing as a macro parameter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-IF-THEN-processing-as-a-macro-parameter/m-p/958271#M374015</link>
      <description>&lt;P&gt;If you want to use the macro language to generate SAS code it is best to start with working SAS code.&lt;/P&gt;
&lt;P&gt;So perhaps can start with this code, which produces your requested results for the example input.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql ;
create table want as
select pt
     , (max(pt=1)
    or max(pt=2)
    or max(pt=3 and DV &amp;lt; 6)
       ) as flag
from x
group by Pt
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now decide which part of that code you need to change.&amp;nbsp; Is it the list of values?&amp;nbsp; Then change the code to use macro variables and set the macro variables to values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let list1=1;
%let list2=2;
%let list3=3;
proc sql ;
create table want as
select pt
     , (max(pt in (&amp;amp;list1))
    or max(pt in (&amp;amp;list2))
    or max(pt in (&amp;amp;list3) and DV &amp;lt; 6)
       ) as flag
from x
group by Pt
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now you can change the values of the macro variables and see if it works as expected.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let list1=11 23 45;
%let list2=22 44;
%let list3=13 56;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Once you get that working wrap it in a macro definition using those macro variable names as the parameters.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Feb 2025 20:11:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-IF-THEN-processing-as-a-macro-parameter/m-p/958271#M374015</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-02-04T20:11:00Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional %IF %THEN processing as a macro parameter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-IF-THEN-processing-as-a-macro-parameter/m-p/958273#M374016</link>
      <description>&lt;P&gt;Thanks, Tom.&amp;nbsp; Appreciate your continued effort to help me with this.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As to the WHY?&amp;nbsp; I have (sometimes long) lists of codes that vary usually by one code.&amp;nbsp; &amp;nbsp;As I explained in the original post, I am trying to avoid re-typing these lists.&amp;nbsp; Say I have 15 codes for DV=6 and those same 15 plus one more for DV=5.&amp;nbsp; I'm trying to add that one code conditionally on the value of DV without the need to re-type.&amp;nbsp; The lists are also changing all the time so, when a change happens, I don't want to edit the list in multiple places.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've entertained the idea of using %LET macro variable assignments but there are dozens of these lists many with permutation.&amp;nbsp; I am afraid that a code with &amp;amp;MacroVariables would become even less readable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope that helps you understad the puruit here.&amp;nbsp; Thanks again.&lt;/P&gt;</description>
      <pubDate>Tue, 04 Feb 2025 20:22:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-IF-THEN-processing-as-a-macro-parameter/m-p/958273#M374016</guid>
      <dc:creator>Haris</dc:creator>
      <dc:date>2025-02-04T20:22:25Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional %IF %THEN processing as a macro parameter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-IF-THEN-processing-as-a-macro-parameter/m-p/958275#M374017</link>
      <description>&lt;P&gt;If you have large lists leave them in DATA, not macro variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data lists;
   infile cards truncover;
   input name :$32. value $100.;
cards;
baselist 2 
lt6dvlist &amp;amp;baselist 4
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now you can use that to create macro variables.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  set lists;
  call symputx(name,value);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And if you print the value you see the full list.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;32   %put &amp;amp;=baselist;
BASELIST=2
33   %put &amp;amp;=lt6dvlist;
LT6DVLIST=2 4
&lt;/PRE&gt;
&lt;P&gt;But the actual value includes the reference to the other list&lt;/P&gt;
&lt;PRE&gt;34   %put baselist=%superq(baselist);
baselist=2
35   %put lt6dvlist=%superq(lt6dvlist);
lt6dvlist=&amp;amp;baselist 4
&lt;/PRE&gt;
&lt;P&gt;You can probably get similar results just in macro code but you will need recreate the macro variable if the referenced macro variable changes.&lt;/P&gt;
&lt;PRE&gt;42   %let lt6dvlist=&amp;amp;baselist 3;
43   %put &amp;amp;lt6dvlist;
2 3
44   %put lt6dvlist=%superq(lt6dvlist);
lt6dvlist=2 3
&lt;/PRE&gt;
&lt;P&gt;Also if the list is in dataset you can either use the dataset in your queries.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where pt in (select pt from lists where name='baselist')&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or use the dataset to generate code into a text file.&amp;nbsp; So code list this&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename code temp;
data _null_;
  set lists;
  file code;
  put ', max(pt in (' list ')) as ' name ;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Will generate lines like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;, max(pt in (2 )) as baselist
, max(pt in (&amp;amp;baselist 4 )) as lt6dvlist&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Which you can use %INCLUDE add to you program.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Feb 2025 20:37:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-IF-THEN-processing-as-a-macro-parameter/m-p/958275#M374017</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-02-04T20:37:44Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional %IF %THEN processing as a macro parameter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-IF-THEN-processing-as-a-macro-parameter/m-p/958276#M374018</link>
      <description>&lt;P&gt;Yes, indeed!&amp;nbsp; A dataset for various code combination is something we're looking into as well.&amp;nbsp; The combinations we need to cover are quite extensive!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Some times its as simple as CC1 = A &amp;amp; B.&amp;nbsp; That is, if a patient has A and B the she meets criteria for CC1.&amp;nbsp; Slightly more complicated CC2 = A &amp;amp; IN (B, C).&amp;nbsp; Other times all three are required and it's CC3 = A &amp;amp; B &amp;amp; C.&amp;nbsp; And then you get two but not the third for CC4 = A &amp;amp; B &amp;amp; (NOT C).&amp;nbsp; And so on, and so on, and so on with about 200 base codes combining every which way two, three, four, ... fifteen at a time.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for your input!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Feb 2025 20:52:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-IF-THEN-processing-as-a-macro-parameter/m-p/958276#M374018</guid>
      <dc:creator>Haris</dc:creator>
      <dc:date>2025-02-04T20:52:37Z</dc:date>
    </item>
  </channel>
</rss>

