<?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: Convert macro variable to numeric in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Convert-macro-variable-to-numeric/m-p/539374#M148606</link>
    <description>Better yet, skip the complications:&lt;BR /&gt;&lt;BR /&gt;Days ="&amp;amp;sysdate9"d - startdate;&lt;BR /&gt;&lt;BR /&gt;There is no reason to break the current date into pieces and reassemble the pieces.</description>
    <pubDate>Thu, 28 Feb 2019 16:46:31 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2019-02-28T16:46:31Z</dc:date>
    <item>
      <title>Convert macro variable to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-macro-variable-to-numeric/m-p/539366#M148599</link>
      <description>&lt;PRE&gt;%let sysd= %sysfunc(day("&amp;amp;sysdate"d));
%let sysmonth= %sysfunc(month("&amp;amp;sysdate"d));
%let sysyear= %sysfunc(year("&amp;amp;sysdate"d));

%put &amp;amp;sysd &amp;amp;sysmonth &amp;amp;sysyear;
&lt;BR /&gt;*this is what I tried to do;
*%let sysd= %sysfunc(inputn(&amp;amp;sysd,4.0));
*%put &amp;amp;sysd;


data main4;
set main3;
	startdate=mdy(NMOIPMRI,NJOUPMRI,NANNPMRI);
	enddate=mdy(&amp;amp;sysmonth,&amp;amp;sysd,&amp;amp;sysyear);
vehi_age=datdif(startdate,enddate,'act/act');
run;

&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hello,&lt;BR /&gt;I am trying to count the number of days between today and a given date in the past.&lt;/P&gt;&lt;P&gt;I struggle to get the proper variable type to input in the mdy() function with my variables &amp;amp;sysd, &amp;amp;sysmonth, &amp;amp;sysyear.&lt;BR /&gt;&lt;BR /&gt;Could you please help me?&lt;/P&gt;</description>
      <pubDate>Thu, 28 Feb 2019 16:32:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-macro-variable-to-numeric/m-p/539366#M148599</guid>
      <dc:creator>pkopersk</dc:creator>
      <dc:date>2019-02-28T16:32:46Z</dc:date>
    </item>
    <item>
      <title>Re: Convert macro variable to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-macro-variable-to-numeric/m-p/539371#M148603</link>
      <description>&lt;P&gt;So if you macro variables that&amp;nbsp; look like&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;8    %put &amp;amp;=sysd &amp;amp;=sysmonth &amp;amp;=sysyear;
SYSD=27 SYSMONTH=2 SYSYEAR=2019
&lt;/PRE&gt;
&lt;P&gt;And you want to use them in a data step then just use them.&lt;/P&gt;
&lt;PRE&gt;enddate=mdy(&amp;amp;sysmonth,&amp;amp;sysd,&amp;amp;sysyear);&lt;/PRE&gt;
&lt;P&gt;No "conversion" is needed. No more than if you had just typed the digit 2 followed by the digit 7 into your program by hand.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Dates are number of days. If you want the difference in days then just subtract them.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;days = enddate - startdate;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Feb 2019 16:42:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-macro-variable-to-numeric/m-p/539371#M148603</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-02-28T16:42:10Z</dc:date>
    </item>
    <item>
      <title>Re: Convert macro variable to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-macro-variable-to-numeric/m-p/539372#M148604</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/207645"&gt;@pkopersk&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;PRE&gt;%let sysd= %sysfunc(day("&amp;amp;sysdate"d));
%let sysmonth= %sysfunc(month("&amp;amp;sysdate"d));
%let sysyear= %sysfunc(year("&amp;amp;sysdate"d));

%put &amp;amp;sysd &amp;amp;sysmonth &amp;amp;sysyear;
&lt;BR /&gt;*this is what I tried to do;
*%let sysd= %sysfunc(inputn(&amp;amp;sysd,4.0));
*%put &amp;amp;sysd;


data main4;
set main3;
	startdate=mdy(NMOIPMRI,NJOUPMRI,NANNPMRI);
	enddate=mdy(&amp;amp;sysmonth,&amp;amp;sysd,&amp;amp;sysyear);
vehi_age=datdif(startdate,enddate,'act/act');
run;

&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hello,&lt;BR /&gt;I am trying to count the number of days between today and a given date in the past.&lt;/P&gt;
&lt;P&gt;I struggle to get the proper variable type to input in the mdy() function with my variables &amp;amp;sysd, &amp;amp;sysmonth, &amp;amp;sysyear.&lt;BR /&gt;&lt;BR /&gt;Could you please help me?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;No macro variables needed at all.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;All of this is very simple, and can be done in a single data step, by creating enddate differently.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;enddate=today();&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Feb 2019 16:45:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-macro-variable-to-numeric/m-p/539372#M148604</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-02-28T16:45:01Z</dc:date>
    </item>
    <item>
      <title>Re: Convert macro variable to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-macro-variable-to-numeric/m-p/539374#M148606</link>
      <description>Better yet, skip the complications:&lt;BR /&gt;&lt;BR /&gt;Days ="&amp;amp;sysdate9"d - startdate;&lt;BR /&gt;&lt;BR /&gt;There is no reason to break the current date into pieces and reassemble the pieces.</description>
      <pubDate>Thu, 28 Feb 2019 16:46:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-macro-variable-to-numeric/m-p/539374#M148606</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-02-28T16:46:31Z</dc:date>
    </item>
    <item>
      <title>Re: Convert macro variable to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-macro-variable-to-numeric/m-p/539375#M148607</link>
      <description>&lt;P&gt;Your code works for me. What error do you get?&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let sysd= %sysfunc(day("&amp;amp;sysdate"d));
%let sysmonth= %sysfunc(month("&amp;amp;sysdate"d));
%let sysyear= %sysfunc(year("&amp;amp;sysdate"d));

%put &amp;amp;sysd &amp;amp;sysmonth &amp;amp;sysyear;

data _null_;
  startdate=today()-55;
  enddate=mdy(&amp;amp;sysmonth,&amp;amp;sysd,&amp;amp;sysyear);
  vehi_age=datdif(startdate,enddate,'act/act');
  put vehi_age;
  stop;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 28 Feb 2019 16:48:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-macro-variable-to-numeric/m-p/539375#M148607</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-02-28T16:48:42Z</dc:date>
    </item>
  </channel>
</rss>

