<?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 Evaluating macros with non-macros in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Evaluating-macros-with-non-macros/m-p/83552#M18035</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I basically want to check if my inputted year (through the macro), is the same as the year for the variable x (a SAS formatted date).&lt;/P&gt;&lt;P&gt;I cam up with two options:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is this a valid piece of code?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro test(year);&lt;/P&gt;&lt;P&gt;x=year(date);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%if &amp;amp;year.=x %then %do;&lt;/P&gt;&lt;P&gt;*blah blah blah;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What about this next one?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let j = %eval(x - &amp;amp;year.);&lt;/P&gt;&lt;P&gt;if &amp;amp;j.=0 then do;&lt;/P&gt;&lt;P&gt;*blah blah blah;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 22 May 2013 21:40:21 GMT</pubDate>
    <dc:creator>itemsong</dc:creator>
    <dc:date>2013-05-22T21:40:21Z</dc:date>
    <item>
      <title>Evaluating macros with non-macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Evaluating-macros-with-non-macros/m-p/83552#M18035</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I basically want to check if my inputted year (through the macro), is the same as the year for the variable x (a SAS formatted date).&lt;/P&gt;&lt;P&gt;I cam up with two options:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is this a valid piece of code?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro test(year);&lt;/P&gt;&lt;P&gt;x=year(date);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%if &amp;amp;year.=x %then %do;&lt;/P&gt;&lt;P&gt;*blah blah blah;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What about this next one?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let j = %eval(x - &amp;amp;year.);&lt;/P&gt;&lt;P&gt;if &amp;amp;j.=0 then do;&lt;/P&gt;&lt;P&gt;*blah blah blah;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 22 May 2013 21:40:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Evaluating-macros-with-non-macros/m-p/83552#M18035</guid>
      <dc:creator>itemsong</dc:creator>
      <dc:date>2013-05-22T21:40:21Z</dc:date>
    </item>
    <item>
      <title>Re: Evaluating macros with non-macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Evaluating-macros-with-non-macros/m-p/83553#M18036</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think your mixing up macro code and data step code. &lt;/P&gt;&lt;P&gt;First part the answer is no. &lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Lucida Grande', Arial, Helvetica, sans-serif; background-color: #ffffff;"&gt;What is X? It isn't in a data set or stored anywhere. You can make it a macro variable. But to evaluate functions not in a datastep you need to use either %eval or %sysfunc depending on what you're trying to do. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Lucida Grande', Arial, Helvetica, sans-serif; background-color: #ffffff;"&gt;The code that is BLAH BLAH must also be valid. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Lucida Grande', Arial, Helvetica, sans-serif; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Lucida Grande', Arial, Helvetica, sans-serif; background-color: #ffffff;"&gt;If the second set of code isn't in a datastep then it also isn't valid. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Lucida Grande', Arial, Helvetica, sans-serif; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Lucida Grande', Arial, Helvetica, sans-serif; background-color: #ffffff;"&gt;The first one is closest I think, except where does the date come from? Is it a variable because it doesn't look to be in a data step either.&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Lucida Grande', Arial, Helvetica, sans-serif; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Lucida Grande', Arial, Helvetica, sans-serif; background-color: #ffffff;"&gt;You probably need to provide more details of what you're trying to do.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Lucida Grande', Arial, Helvetica, sans-serif; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Lucida Grande', Arial, Helvetica, sans-serif; background-color: #ffffff;"&gt;*if date is a macro variable and this is in macro code;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Lucida Grande', Arial, Helvetica, sans-serif; background-color: #ffffff;"&gt;%if &amp;amp;year.=%sysfunc(year(&amp;amp;date)) %then %do;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Lucida Grande', Arial, Helvetica, sans-serif; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Lucida Grande', Arial, Helvetica, sans-serif; background-color: #ffffff;"&gt;or &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Lucida Grande', Arial, Helvetica, sans-serif; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Lucida Grande', Arial, Helvetica, sans-serif; background-color: #ffffff;"&gt;*if date is a variable and this is in datastep code;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Lucida Grande', Arial, Helvetica, sans-serif; background-color: #ffffff;"&gt;if year(date)=&amp;amp;year then do;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 22 May 2013 22:22:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Evaluating-macros-with-non-macros/m-p/83553#M18036</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2013-05-22T22:22:43Z</dc:date>
    </item>
    <item>
      <title>Re: Evaluating macros with non-macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Evaluating-macros-with-non-macros/m-p/83554#M18037</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;To test a variable you need to use actual SAS code.&amp;nbsp; You can reference the macro variable in the code to perform the test.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro test(year);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set mydata ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if year(x) = &amp;amp;year then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ....&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;%mend test;&lt;/P&gt;&lt;P&gt;%test(2010);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now if you want the result of the test to effect the macro logic then you can use CALL SYMPUTX to create a macro variable in that data step that can be used later in the macro to control the generation of other code.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 23 May 2013 00:14:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Evaluating-macros-with-non-macros/m-p/83554#M18037</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2013-05-23T00:14:39Z</dc:date>
    </item>
    <item>
      <title>Re: Evaluating macros with non-macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Evaluating-macros-with-non-macros/m-p/83555#M18038</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;So this is all within a datastep--sorry I should've provided the entire code..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So for this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Lucida Grande', Arial, Helvetica, sans-serif; background-color: #ffffff;"&gt;if year(date)=&amp;amp;year then do;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Lucida Grande', Arial, Helvetica, sans-serif; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Lucida Grande', Arial, Helvetica, sans-serif; background-color: #ffffff;"&gt;Do I not need the %if and %then and %do?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Lucida Grande', Arial, Helvetica, sans-serif; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Lucida Grande', Arial, Helvetica, sans-serif; background-color: #ffffff;"&gt;So if year(date)=1995, and &amp;amp;year=1995, then the "do" will be executed?&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 23 May 2013 00:35:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Evaluating-macros-with-non-macros/m-p/83555#M18038</guid>
      <dc:creator>itemsong</dc:creator>
      <dc:date>2013-05-23T00:35:12Z</dc:date>
    </item>
    <item>
      <title>Re: Evaluating macros with non-macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Evaluating-macros-with-non-macros/m-p/83556#M18039</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Macro logic (%IF/%THEN/%ELSE...) are for when you want the macro to conditional output SAS CODE that SAS can then execute.&lt;/P&gt;&lt;P&gt;Once the code is generated and the generated DATA step or PROC is running the macro programming is mainly irrelevant.&lt;/P&gt;&lt;PRE __jive_macro_name="quote" class="jive_text_macro jive_macro_quote"&gt;&lt;SPAN style="font-family: 'Lucida Grande', Arial, Helvetica, sans-serif; background-color: #ffffff;"&gt;So if year(date)=1995, and &amp;amp;year=1995, then the "do" will be executed?&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;If you want to conditionally execute statements based on whether the DATE variable's value for the current observation being processed is equal to the user specified year then you would code&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; IF YEAR(DATE) = &amp;amp;YEAR THEN DO; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .....&lt;/P&gt;&lt;P&gt;&amp;nbsp; END;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If the user calls the macro with YEAR set to 1995 ( %test(year=1995) ) then the code above will become :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; IF YEAR(DATE) = 1995 THEN DO; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .....&lt;/P&gt;&lt;P&gt;&amp;nbsp; END;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Turn on the MPRINT option so that you can see what code the macro has generated.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 23 May 2013 01:18:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Evaluating-macros-with-non-macros/m-p/83556#M18039</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2013-05-23T01:18:20Z</dc:date>
    </item>
  </channel>
</rss>

