<?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: FUNKY RESULT - MACRO VARIABLES in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/FUNKY-RESULT-MACRO-VARIABLES/m-p/137727#M295976</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You are probably creating macro variables with the dates formatted with the hyphens in them.&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;%let valuationDate= 2014-03-31;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;%let maturityDate=&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;2041-05-15&lt;/SPAN&gt; ;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;So when you tried to use %EVAL() to perform arithmetic on them it happily subtracted the month number from the year number and then subtracted the day number from that.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;A value of minus 81 looks right to me.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;You can either tell PROC SQL to format the dates as an integer to get it as a simple number of days and then your subtraction will work.&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;select COL1 format=10. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Our you could tell it to use DATE9 format and then reference them as date literals.&amp;nbsp; You might need to use %sysevalf() instead of %eval() for that to work.&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;select COL1 format=date9.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;...&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #ffffff; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;%let Result=%sysevalf( "&amp;amp;ValuationDate"d - "&amp;amp;MaturityDate"d );&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 09 Sep 2014 20:06:36 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2014-09-09T20:06:36Z</dc:date>
    <item>
      <title>FUNKY RESULT - MACRO VARIABLES</title>
      <link>https://communities.sas.com/t5/SAS-Programming/FUNKY-RESULT-MACRO-VARIABLES/m-p/137721#M295970</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have the following code, which I apply to the attached.csv file. My end goal is to calculate the number of days between the macro variables &amp;amp;MaturityDate and &amp;amp;ValuationDate. Unfortunately, I am not getting a reasonable result (see arrow below). Could someone please provide some insight?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data WORK.NCDebt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; infile '/fmacdata/utility/fin/KBenchmarks/SAS Data/NCDebt_1.csv' dsd lrecl=40000 firstobs=2;&lt;BR /&gt;informat ValuationDate yymmdd.;&lt;BR /&gt;informat MaturityDate mmddyy10.;&lt;BR /&gt;format MaturityDate yymmdd10. ValuationDate yymmdd10.;&lt;BR /&gt;input ValuationDate $ MaturityDate $;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;proc transpose data=Ncdebt&lt;BR /&gt;&amp;nbsp; out=Ncdebt2;&lt;BR /&gt;&amp;nbsp; var ValuationDate MaturityDate;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data Ncdebt3;&lt;BR /&gt;&amp;nbsp; set Ncdebt2(rename=(_NAME_=Var1));&lt;BR /&gt;&amp;nbsp; keep Var1 COL1;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;&amp;nbsp; select COL1&lt;BR /&gt;&amp;nbsp; into: ValuationDate&lt;BR /&gt;&amp;nbsp; from Ncdebt3&lt;BR /&gt;&amp;nbsp; where var1='ValuationDate';&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;&amp;nbsp; select COL1&lt;BR /&gt;&amp;nbsp; into: MaturityDate&lt;BR /&gt;&amp;nbsp; from Ncdebt3&lt;BR /&gt;&amp;nbsp; where var1='MaturityDate';&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let Result=%eval(&amp;amp;ValuationDate-&amp;amp;MaturityDate);&amp;nbsp;&amp;nbsp; ------&amp;gt;THIS PART IS NOT GIVING ME THE CORRECT RESULTS&lt;/P&gt;&lt;P&gt;%put &amp;amp;ValuationDate &amp;amp;MaturityDate &amp;amp;Result;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 09 Sep 2014 18:58:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/FUNKY-RESULT-MACRO-VARIABLES/m-p/137721#M295970</guid>
      <dc:creator>maroulator</dc:creator>
      <dc:date>2014-09-09T18:58:27Z</dc:date>
    </item>
    <item>
      <title>Re: FUNKY RESULT - MACRO VARIABLES</title>
      <link>https://communities.sas.com/t5/SAS-Programming/FUNKY-RESULT-MACRO-VARIABLES/m-p/137722#M295971</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;what do those values look like in a put statement?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;i.e.&lt;/P&gt;&lt;P&gt;%put &amp;amp;valuationDate;&lt;/P&gt;&lt;P&gt;%put &amp;amp;maturityDate;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 09 Sep 2014 19:20:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/FUNKY-RESULT-MACRO-VARIABLES/m-p/137722#M295971</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2014-09-09T19:20:07Z</dc:date>
    </item>
    <item>
      <title>Re: FUNKY RESULT - MACRO VARIABLES</title>
      <link>https://communities.sas.com/t5/SAS-Programming/FUNKY-RESULT-MACRO-VARIABLES/m-p/137723#M295972</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE __jive_macro_name="quote" class="jive_text_macro jive_macro_quote"&gt;
&lt;P&gt;Unfortunately, I am not getting a reasonable result (see arrow below). Could someone please provide some insight?&lt;/P&gt;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __jive_macro_name="quote" class="jive_text_macro jive_macro_quote"&gt;
&lt;P&gt;%let Result=%eval(&amp;amp;ValuationDate-&amp;amp;MaturityDate);&amp;nbsp;&amp;nbsp; ------&amp;gt;THIS PART IS NOT GIVING ME THE CORRECT RESULTS&lt;/P&gt;
&lt;/PRE&gt;&lt;P&gt;What results are you getting? Why are they not reasonable? What did you expect to get?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 09 Sep 2014 19:20:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/FUNKY-RESULT-MACRO-VARIABLES/m-p/137723#M295972</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2014-09-09T19:20:33Z</dc:date>
    </item>
    <item>
      <title>Re: FUNKY RESULT - MACRO VARIABLES</title>
      <link>https://communities.sas.com/t5/SAS-Programming/FUNKY-RESULT-MACRO-VARIABLES/m-p/137724#M295973</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;ValuationDate resolves to 2014-03-31&lt;/P&gt;&lt;P&gt;MaturityDate resolves to 2041-05-15&lt;/P&gt;&lt;P&gt;Result resolves to -81, whereas I would have expected Result to resolve to 9907.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 09 Sep 2014 19:53:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/FUNKY-RESULT-MACRO-VARIABLES/m-p/137724#M295973</guid>
      <dc:creator>maroulator</dc:creator>
      <dc:date>2014-09-09T19:53:13Z</dc:date>
    </item>
    <item>
      <title>Re: FUNKY RESULT - MACRO VARIABLES</title>
      <link>https://communities.sas.com/t5/SAS-Programming/FUNKY-RESULT-MACRO-VARIABLES/m-p/137725#M295974</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This is what you're passing to SAS then&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2014-03-31-2041-05-15 which does actually equal -81.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SAS isn't recognizing it those values as dates, you'll need to change them to be actual sas dates somehow, either when you create them or in the calculation step. I'd recommend the creation step.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;proc sql;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp; select input(COL1, anydtdte.)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp; into: MaturityDate&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp; from Ncdebt3&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp; where var1='MaturityDate';&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;quit;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 09 Sep 2014 19:58:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/FUNKY-RESULT-MACRO-VARIABLES/m-p/137725#M295974</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2014-09-09T19:58:06Z</dc:date>
    </item>
    <item>
      <title>Re: FUNKY RESULT - MACRO VARIABLES</title>
      <link>https://communities.sas.com/t5/SAS-Programming/FUNKY-RESULT-MACRO-VARIABLES/m-p/137726#M295975</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN class="kw6"&gt;If you can adjust your date format, it can be acheived easily with the below code. Hope it will help you a bit&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="kw6"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;%macro diff_date&lt;BR /&gt;&amp;nbsp;&amp;nbsp; (begin = &lt;BR /&gt;&amp;nbsp;&amp;nbsp; ,end&amp;nbsp;&amp;nbsp; = today()&lt;BR /&gt;&amp;nbsp;&amp;nbsp; ,y&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = years&lt;BR /&gt;&amp;nbsp;&amp;nbsp; ,m&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = months&lt;BR /&gt;&amp;nbsp;&amp;nbsp; ,d&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = days&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; );&lt;BR /&gt; *--number of full months between dates;&lt;BR /&gt; &amp;amp;m = intck('month', &amp;amp;begin, &amp;amp;end)&lt;BR /&gt;&amp;nbsp; -(day(&amp;amp;end) &amp;lt; day(&amp;amp;begin));&lt;/P&gt;&lt;P&gt; *--number of full years between dates;&lt;BR /&gt; &amp;amp;y = floor(&amp;amp;m / 12);&lt;/P&gt;&lt;P&gt; *--remainder of full months after removing full years;&lt;BR /&gt; &amp;amp;m = mod(&amp;amp;m , 12);&lt;/P&gt;&lt;P&gt; *--number of days remaining after removing years and months;&lt;BR /&gt; &amp;amp;d = ( day(&amp;amp;end) &amp;lt; day(&amp;amp;begin)) &lt;BR /&gt;&amp;nbsp; * day(intnx('month',&amp;amp;begin,1)-1) &lt;BR /&gt;&amp;nbsp; + day(&amp;amp;end) &lt;BR /&gt;&amp;nbsp; - day(&amp;amp;begin);&lt;BR /&gt;%mend;&lt;/P&gt;&lt;P&gt;data _null_;&lt;BR /&gt; ValuationDate= '31jan2008'd;&lt;BR /&gt; MaturityDate= '01mar2009'd;&lt;/P&gt;&lt;P&gt; %diff_date(begin=ValuationDate, end=MaturityDate)&lt;/P&gt;&lt;P&gt;&lt;SPAN class="kw3"&gt;put&lt;/SPAN&gt; years= months= days= ;&lt;BR /&gt; run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG alt="Capture.JPG" class="jive-image" src="https://communities.sas.com/legacyfs/online/7358_Capture.JPG" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 09 Sep 2014 20:01:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/FUNKY-RESULT-MACRO-VARIABLES/m-p/137726#M295975</guid>
      <dc:creator>Hima</dc:creator>
      <dc:date>2014-09-09T20:01:41Z</dc:date>
    </item>
    <item>
      <title>Re: FUNKY RESULT - MACRO VARIABLES</title>
      <link>https://communities.sas.com/t5/SAS-Programming/FUNKY-RESULT-MACRO-VARIABLES/m-p/137727#M295976</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You are probably creating macro variables with the dates formatted with the hyphens in them.&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;%let valuationDate= 2014-03-31;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;%let maturityDate=&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;2041-05-15&lt;/SPAN&gt; ;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;So when you tried to use %EVAL() to perform arithmetic on them it happily subtracted the month number from the year number and then subtracted the day number from that.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;A value of minus 81 looks right to me.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;You can either tell PROC SQL to format the dates as an integer to get it as a simple number of days and then your subtraction will work.&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;select COL1 format=10. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Our you could tell it to use DATE9 format and then reference them as date literals.&amp;nbsp; You might need to use %sysevalf() instead of %eval() for that to work.&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;select COL1 format=date9.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;...&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #ffffff; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;%let Result=%sysevalf( "&amp;amp;ValuationDate"d - "&amp;amp;MaturityDate"d );&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 09 Sep 2014 20:06:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/FUNKY-RESULT-MACRO-VARIABLES/m-p/137727#M295976</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2014-09-09T20:06:36Z</dc:date>
    </item>
  </channel>
</rss>

