<?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: If Statements inside a macro to create a macro variable in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/If-Statements-inside-a-macro-to-create-a-macro-variable/m-p/368954#M24136</link>
    <description>&lt;P&gt;DATA steps are not capable of executing macro language statements. &amp;nbsp;All of the statements you used there are not part of the DATA step at all.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are a limited number of DATA step statements that function as an interface between the DATA step and macro language. &amp;nbsp;Here is an example of what you might do:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let beta=0;&lt;/P&gt;
&lt;P&gt;data _null_;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set STRESS_1.BETACOEFFS_TCE_RWA;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;if index(upcase(_DEPVAR_), '01_BETA') then call symputx('beta', 1);&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Assuming that your data set contains just one observation as you indicated, that should give &amp;amp;BETA the proper value.&lt;/P&gt;</description>
    <pubDate>Tue, 20 Jun 2017 21:28:07 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2017-06-20T21:28:07Z</dc:date>
    <item>
      <title>If Statements inside a macro to create a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/If-Statements-inside-a-macro-to-create-a-macro-variable/m-p/368948#M24133</link>
      <description>&lt;P&gt;Hello, I am very new to SAS EG (about a month now) and I have this specific problem inside one of my macros:&lt;/P&gt;&lt;P&gt;So I have this table "STRESS_1.BETACOEFFS_TCE_RWA" that contains only one row of many variables. I want to create a macro variable "&amp;amp;BETA." that takes the value of 1 if the variable "_DEPVAR_" in my table is called "TCE_RWA_01_Beta", or has "01_Beta" in the name (both works out for me)&amp;nbsp;and the value of 0 if not (AKA if it is called "TCE_RWA" or doesn't contain "01_Beta"). Now, I know for a fact that the small code below should give the &amp;amp;BETA. macro the value of 1, since it is what I read and yet I always get the value of 0 with the %put statement and in my results of my bigger macro. I think the problem comes from the if statement. I tried many many different things but&amp;nbsp;I just can't figure it out. I need some help, thanks in advance!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;[...]&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set STRESS_1.BETACOEFFS_TCE_RWA;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %if&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; _DEPVAR_ = TCE_RWA_01_Beta &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%then &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%do&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; BETA=1;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %end&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %else&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%do&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; BETA=0;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %end&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%put&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; TCE_RWA_01_Beta should be 1 but is &amp;amp;BETA.;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;[...]&lt;/P&gt;&lt;BR /&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/13968i23847877A09AD634/image-size/large?v=1.0&amp;amp;px=600" border="0" alt="example.jpg" title="example.jpg" /&gt;</description>
      <pubDate>Tue, 20 Jun 2017 21:09:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/If-Statements-inside-a-macro-to-create-a-macro-variable/m-p/368948#M24133</guid>
      <dc:creator>x2PSx</dc:creator>
      <dc:date>2017-06-20T21:09:34Z</dc:date>
    </item>
    <item>
      <title>Re: If Statements inside a macro to create a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/If-Statements-inside-a-macro-to-create-a-macro-variable/m-p/368951#M24134</link>
      <description>&lt;P&gt;Is that code inside a SAS macro (i.e., SAS code that starts with %macro somename; and ends with $mend;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;or is it just open code?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Jun 2017 21:20:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/If-Statements-inside-a-macro-to-create-a-macro-variable/m-p/368951#M24134</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-06-20T21:20:48Z</dc:date>
    </item>
    <item>
      <title>Re: If Statements inside a macro to create a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/If-Statements-inside-a-macro-to-create-a-macro-variable/m-p/368952#M24135</link>
      <description>Yes it is inside of my MACRO with the MEND as well at the end. I've done macros before this is not the problem, it's my if statement that doesn't register. Thank you&lt;BR /&gt;</description>
      <pubDate>Tue, 20 Jun 2017 21:23:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/If-Statements-inside-a-macro-to-create-a-macro-variable/m-p/368952#M24135</guid>
      <dc:creator>x2PSx</dc:creator>
      <dc:date>2017-06-20T21:23:49Z</dc:date>
    </item>
    <item>
      <title>Re: If Statements inside a macro to create a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/If-Statements-inside-a-macro-to-create-a-macro-variable/m-p/368954#M24136</link>
      <description>&lt;P&gt;DATA steps are not capable of executing macro language statements. &amp;nbsp;All of the statements you used there are not part of the DATA step at all.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are a limited number of DATA step statements that function as an interface between the DATA step and macro language. &amp;nbsp;Here is an example of what you might do:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let beta=0;&lt;/P&gt;
&lt;P&gt;data _null_;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set STRESS_1.BETACOEFFS_TCE_RWA;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;if index(upcase(_DEPVAR_), '01_BETA') then call symputx('beta', 1);&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Assuming that your data set contains just one observation as you indicated, that should give &amp;amp;BETA the proper value.&lt;/P&gt;</description>
      <pubDate>Tue, 20 Jun 2017 21:28:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/If-Statements-inside-a-macro-to-create-a-macro-variable/m-p/368954#M24136</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-06-20T21:28:07Z</dc:date>
    </item>
    <item>
      <title>Re: If Statements inside a macro to create a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/If-Statements-inside-a-macro-to-create-a-macro-variable/m-p/368962#M24137</link>
      <description>&lt;P&gt;Since the text (!) _DEPVAR_ is never equal to the text TCE_RWA_01_Beta, the %if condition evaluates to false, and macro variable beta is set to 0.&lt;/P&gt;
&lt;P&gt;Keep in mind that the macro processor is a PREprocessor and macro statements are resolved before the data step is even compiled.&lt;/P&gt;</description>
      <pubDate>Tue, 20 Jun 2017 21:55:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/If-Statements-inside-a-macro-to-create-a-macro-variable/m-p/368962#M24137</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-06-20T21:55:27Z</dc:date>
    </item>
    <item>
      <title>Re: If Statements inside a macro to create a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/If-Statements-inside-a-macro-to-create-a-macro-variable/m-p/369132#M24143</link>
      <description>Thank you, I wasn't aware of that fact. This simple code did it for me!</description>
      <pubDate>Wed, 21 Jun 2017 13:15:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/If-Statements-inside-a-macro-to-create-a-macro-variable/m-p/369132#M24143</guid>
      <dc:creator>x2PSx</dc:creator>
      <dc:date>2017-06-21T13:15:43Z</dc:date>
    </item>
  </channel>
</rss>

