<?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 statement within macro not working correctly in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Conditional-statement-within-macro-not-working-correctly/m-p/866737#M342308</link>
    <description>&lt;P&gt;Hello,&lt;BR /&gt;&lt;BR /&gt;Thank you for your follow up.&amp;nbsp; PROB is a column in the dataset "stats" containing a numerical value.&amp;nbsp; Based on this numerical value would depend which proc glm statement I want to run.&lt;BR /&gt;&lt;BR /&gt;Thank you,&lt;BR /&gt;Jeff S. O.&lt;/P&gt;</description>
    <pubDate>Tue, 28 Mar 2023 14:40:50 GMT</pubDate>
    <dc:creator>Jolly1289</dc:creator>
    <dc:date>2023-03-28T14:40:50Z</dc:date>
    <item>
      <title>Conditional statement within macro not working correctly</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-statement-within-macro-not-working-correctly/m-p/866734#M342306</link>
      <description>&lt;P&gt;Hello,&lt;BR /&gt;&lt;BR /&gt;I am working on creating a stability analysis program using macros to assist with our redundant stability analysis that we perform.&amp;nbsp; For part of the program, I need to use a conditional statement to determine with model to run.&amp;nbsp; However, in my example code I am unable to get the conditional statement to correctly execute based on a p-value that I have save into a dataset.&amp;nbsp; The section of code that is giving me the issue is:&lt;BR /&gt;&lt;BR /&gt;%macro Stability();&lt;BR /&gt;data stats;&lt;BR /&gt;set stats;&lt;BR /&gt;%if PROB &amp;gt; 0.25 %then %do;&lt;BR /&gt;proc glm data=stability;&lt;BR /&gt;model RP=time;&lt;BR /&gt;run;&lt;BR /&gt;%end;&lt;BR /&gt;%else %do;&lt;BR /&gt;proc glm data=stability;&lt;BR /&gt;class batch;&lt;BR /&gt;model RP=batch time batch*time;&lt;BR /&gt;run;&lt;BR /&gt;%end;&lt;BR /&gt;%mend Stability;&lt;BR /&gt;%Stability();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;where "%if PROB &amp;gt; 0.25 %then %do;" is not leading to the use of the correct proc glm procedure being executed.&amp;nbsp; Basically, in this part of the code I am trying to automate the process of testing for poolability of data across batches or if the batches need to be kept separate.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I have also attached an entire SAS code file for a full example.&amp;nbsp; Any help would be greatly appreciated.&lt;BR /&gt;&lt;BR /&gt;Thank you,&lt;BR /&gt;Jeff S. O.&lt;/P&gt;</description>
      <pubDate>Tue, 28 Mar 2023 14:20:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-statement-within-macro-not-working-correctly/m-p/866734#M342306</guid>
      <dc:creator>Jolly1289</dc:creator>
      <dc:date>2023-03-28T14:20:27Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional statement within macro not working correctly</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-statement-within-macro-not-working-correctly/m-p/866736#M342307</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%if PROB &amp;gt; 0.25 %then %do;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This will never work, as to use %IF requires you test a macro variable against some constant. You can't test something named PROB as the macro facility will treat that as text and not a number. However this should work:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%if &amp;amp;PROB &amp;gt; 0.25 %then %do;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;here I have used a macro variable &amp;amp;PROB — do you have such a macro variable? It's not obvious.&lt;/P&gt;</description>
      <pubDate>Tue, 28 Mar 2023 14:28:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-statement-within-macro-not-working-correctly/m-p/866736#M342307</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-03-28T14:28:53Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional statement within macro not working correctly</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-statement-within-macro-not-working-correctly/m-p/866737#M342308</link>
      <description>&lt;P&gt;Hello,&lt;BR /&gt;&lt;BR /&gt;Thank you for your follow up.&amp;nbsp; PROB is a column in the dataset "stats" containing a numerical value.&amp;nbsp; Based on this numerical value would depend which proc glm statement I want to run.&lt;BR /&gt;&lt;BR /&gt;Thank you,&lt;BR /&gt;Jeff S. O.&lt;/P&gt;</description>
      <pubDate>Tue, 28 Mar 2023 14:40:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-statement-within-macro-not-working-correctly/m-p/866737#M342308</guid>
      <dc:creator>Jolly1289</dc:creator>
      <dc:date>2023-03-28T14:40:50Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional statement within macro not working correctly</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-statement-within-macro-not-working-correctly/m-p/866738#M342309</link>
      <description>&lt;P&gt;Do you really use this?&lt;/P&gt;
&lt;PRE&gt;data stats;
set stats;&lt;/PRE&gt;
&lt;P&gt;As shown a&amp;nbsp; complete waste of CPU cycles as you copy data with no changes into the same data set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note: If you are going to work with macro programming I &lt;STRONG&gt;strongly suggest&lt;/STRONG&gt; that you &lt;STRONG&gt;always &lt;/STRONG&gt;include a RUN; statement to end every procedure.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You state : " conditional statement to correctly execute based on a p-value that I have save into a dataset. ". I see no reference to any variable in a data set that might be used in that manner.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;If&lt;/STRONG&gt; you intend to use a value from from a data set as a comparison with macro code you first have to make a MACRO variable. That would use the function CALL SYMPUTX. And since your reference a p-value then you need to take control of converting that p_value to the text that a macro comparison will use.&lt;/P&gt;
&lt;P&gt;I suspect that you need something like :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data _null_;
   set stats;
   call symputx('prob', put(pvaluevariablename,f4.2) );
run;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;%if &amp;amp;prob. &amp;gt; 0.25 %then %do;
&lt;/PRE&gt;
&lt;P&gt;The format you use to convert the pvalue to text is up to you. However you want to be aware of probably rounding of the p-value AND how the comparison works.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Mar 2023 14:46:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-statement-within-macro-not-working-correctly/m-p/866738#M342309</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-03-28T14:46:04Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional statement within macro not working correctly</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-statement-within-macro-not-working-correctly/m-p/866742#M342311</link>
      <description>&lt;P&gt;Thank you very much ballardw.&amp;nbsp; I completely forgot about the call symputx statements (picking up SAS first the first time in a few years).&amp;nbsp; I was thinking I could load the data sets within the macro and being able to pull directly from them without needing to do anything else.&amp;nbsp; Thank you very much!&lt;/P&gt;</description>
      <pubDate>Tue, 28 Mar 2023 14:59:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-statement-within-macro-not-working-correctly/m-p/866742#M342311</guid>
      <dc:creator>Jolly1289</dc:creator>
      <dc:date>2023-03-28T14:59:58Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional statement within macro not working correctly</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-statement-within-macro-not-working-correctly/m-p/866750#M342316</link>
      <description>&lt;P&gt;DATA steps contain a tool to make this easy.&amp;nbsp; You don't need CALL SYMPUT at all.&amp;nbsp; You don't need a macro definition.&amp;nbsp; To execute one set of code or another after your DATA step ends, here is the way to do it:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
set stats;
if PROB &amp;gt; 0.25 then call execute(
'proc glm data=stability;
model RP=time;
run;');
else call execute(
'proc glm data=stability;
class batch;
model RP=batch time batch*time;
run;');
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If STATS contains multiple observations, you may need to add to the logic to make sure you execute this logic just once.&lt;/P&gt;</description>
      <pubDate>Tue, 28 Mar 2023 15:55:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-statement-within-macro-not-working-correctly/m-p/866750#M342316</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2023-03-28T15:55:01Z</dc:date>
    </item>
  </channel>
</rss>

