<?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 Variable String to  date7. format in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Convert-Variable-String-to-date7-format/m-p/762431#M241413</link>
    <description>&lt;P&gt;If you want to compare the macro variable to a date value then don't format it just create the date.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want the same date as last year you should use %sysfunc( intnx(year, %sysfunc(today()),-1,S)&lt;/P&gt;
&lt;P&gt;If you want the previous year then %eval(%sysfunc(year(%sysfunc(today())) -1) might be easier&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You really should show what value you think you want to create.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Macro variables do not resolve when they appear inside single quotes. So '&amp;amp;Last_YY.'d is not a valid date at all, "&amp;amp;last_yy"d might. I am not sure what you expect it to be.&lt;/P&gt;</description>
    <pubDate>Thu, 19 Aug 2021 02:36:10 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2021-08-19T02:36:10Z</dc:date>
    <item>
      <title>Convert Variable String to  date7. format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-Variable-String-to-date7-format/m-p/762430#M241412</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Currently in my SQL code written in SAS this is being used:-&lt;/P&gt;&lt;P&gt;Where date_column ='01AUG20'd&amp;nbsp;&lt;/P&gt;&lt;P&gt;(20 is for last year)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to change it to make it dynamic and i have prepared below to replace this hard code&amp;nbsp;&lt;/P&gt;&lt;P&gt;I. Below to make the variable&lt;/P&gt;&lt;P&gt;%LET Last_Year= %substr(%sysfunc(intnx(day,%sysfunc(today()),-365),date7.),3);&lt;BR /&gt;/*,3,2); */&lt;BR /&gt;%LET Last_YY = 01&amp;amp;Last_Year. ;&lt;BR /&gt;%PUT &amp;amp;Last_YY.;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;II. This is how i used it but its giving error&amp;nbsp;&lt;/P&gt;&lt;P&gt;WHERE datecolumn=&amp;nbsp; '&amp;amp;Last_YY.'d&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But this is giving error. how can i use this variable LAST_YY as a date for this WHERE clause&lt;/P&gt;&lt;P&gt;Error:-&lt;/P&gt;&lt;P&gt;Invalid date/time/datetime constant '&amp;amp;Last_YY.'d.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kindly provide the help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Raman&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 19 Aug 2021 02:18:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-Variable-String-to-date7-format/m-p/762430#M241412</guid>
      <dc:creator>RDS2020</dc:creator>
      <dc:date>2021-08-19T02:18:32Z</dc:date>
    </item>
    <item>
      <title>Re: Convert Variable String to  date7. format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-Variable-String-to-date7-format/m-p/762431#M241413</link>
      <description>&lt;P&gt;If you want to compare the macro variable to a date value then don't format it just create the date.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want the same date as last year you should use %sysfunc( intnx(year, %sysfunc(today()),-1,S)&lt;/P&gt;
&lt;P&gt;If you want the previous year then %eval(%sysfunc(year(%sysfunc(today())) -1) might be easier&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You really should show what value you think you want to create.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Macro variables do not resolve when they appear inside single quotes. So '&amp;amp;Last_YY.'d is not a valid date at all, "&amp;amp;last_yy"d might. I am not sure what you expect it to be.&lt;/P&gt;</description>
      <pubDate>Thu, 19 Aug 2021 02:36:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-Variable-String-to-date7-format/m-p/762431#M241413</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-08-19T02:36:10Z</dc:date>
    </item>
    <item>
      <title>Re: Convert Variable String to  date7. format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-Variable-String-to-date7-format/m-p/762432#M241414</link>
      <description>&lt;P&gt;So the immediate cause of the error is that the macro processors ignores strings in single quotes.&amp;nbsp; Use double quotes instead.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where datecolumn=  "&amp;amp;Last_YY."d&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now to the rest of your code.&lt;/P&gt;
&lt;P&gt;Do not use only two digits for years. The extra two bytes won't cost you anything and could save you a LOT of headaches.&lt;/P&gt;
&lt;P&gt;What is the -365 in your code?&amp;nbsp; Are you trying to move back a year? Why use 365 days? What if last year was a leap year?&lt;/P&gt;
&lt;P&gt;What is the SUBSTR(xxx,3) for?&amp;nbsp; Are you trying to remove the day of month so you can replace it with 01?&amp;nbsp; If so why not use MONTH interval to begin with?&lt;/P&gt;
&lt;P&gt;Why do you need to have the date value used in the WHERE clause as a date literal instead of just using the actual number of days since 1960?&amp;nbsp; The SAS code does not care whether humans can tell what date the number means.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let last_yy = %sysfunc(intnx(month,%sysfunc(date()),-12,b));
%let last_year = %sysfunc(putn(&amp;amp;last_yy,monyy7.));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;PRE&gt;613   %put &amp;amp;=last_yy &amp;amp;=last_year;
LAST_YY=22128 LAST_YEAR=AUG2020
&lt;/PRE&gt;</description>
      <pubDate>Thu, 19 Aug 2021 02:50:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-Variable-String-to-date7-format/m-p/762432#M241414</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-08-19T02:50:21Z</dc:date>
    </item>
    <item>
      <title>Re: Convert Variable String to  date7. format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-Variable-String-to-date7-format/m-p/762440#M241422</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp; ,&lt;/P&gt;&lt;P&gt;Thanks for replying , and yes you are on the spot with the solution.&lt;/P&gt;&lt;P&gt;I was try to remove first date and start from month for this .&lt;/P&gt;&lt;P&gt;Didnt wanna to remove 01 from the date as code wasnt mine and didnt wanna to make any unexpected changes.&lt;/P&gt;&lt;P&gt;But appreciate your&amp;nbsp; help will use them.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Raman&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 19 Aug 2021 03:26:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-Variable-String-to-date7-format/m-p/762440#M241422</guid>
      <dc:creator>RDS2020</dc:creator>
      <dc:date>2021-08-19T03:26:05Z</dc:date>
    </item>
  </channel>
</rss>

