<?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 Date Manipulation in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Date-Manipulation/m-p/172425#M301620</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Howdy,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm new to programming and trying to figure out the best way to do the following:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a macro variable "Start_Date" which will be changed by users:&lt;/P&gt;&lt;P&gt;%let Start_Date = '06FEB2013:0:0:0'dt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'd like to take the year of the "Start_Date" value and find the first day of the year before. &lt;/P&gt;&lt;P&gt;The desired output using the date above would be '01JAN2012:0:0:0'dt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Conceptually I loosely know of two routes to take....&lt;/P&gt;&lt;P&gt;Route 1: I could turn my date into a string, grab the "2013" off my string, create a string resembling a date, then turn this string into a date, arriving at the desired first day of the year.&lt;/P&gt;&lt;P&gt;Something like:&lt;/P&gt;&lt;P&gt;Date = 2/06/2013&lt;/P&gt;&lt;P&gt;=String(2/06/2013)&lt;/P&gt;&lt;P&gt;output: 20130206&lt;/P&gt;&lt;P&gt;=Left(20130206,1,4)&lt;/P&gt;&lt;P&gt;output: 2013&lt;/P&gt;&lt;P&gt;=1&amp;amp;"/"&amp;amp;1&amp;amp;"/"&amp;amp;2013&lt;/P&gt;&lt;P&gt;output: 1/1/2013&lt;/P&gt;&lt;P&gt;=Datevalue(1/1/2013)&lt;/P&gt;&lt;P&gt;Output: 1/1/2013 in date format or 1/1/2012 if subtracting one from the current year.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Route 2: use a SAS function for date shift to calculate at the correct date. In searching the forums I've seen intnx and mdy used in what looks like a similar goal.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Would anyone have an efficient route to pursue? &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;TS&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 07 Jan 2015 14:51:17 GMT</pubDate>
    <dc:creator>GalacticAbacus</dc:creator>
    <dc:date>2015-01-07T14:51:17Z</dc:date>
    <item>
      <title>Date Manipulation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-Manipulation/m-p/172425#M301620</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Howdy,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm new to programming and trying to figure out the best way to do the following:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a macro variable "Start_Date" which will be changed by users:&lt;/P&gt;&lt;P&gt;%let Start_Date = '06FEB2013:0:0:0'dt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'd like to take the year of the "Start_Date" value and find the first day of the year before. &lt;/P&gt;&lt;P&gt;The desired output using the date above would be '01JAN2012:0:0:0'dt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Conceptually I loosely know of two routes to take....&lt;/P&gt;&lt;P&gt;Route 1: I could turn my date into a string, grab the "2013" off my string, create a string resembling a date, then turn this string into a date, arriving at the desired first day of the year.&lt;/P&gt;&lt;P&gt;Something like:&lt;/P&gt;&lt;P&gt;Date = 2/06/2013&lt;/P&gt;&lt;P&gt;=String(2/06/2013)&lt;/P&gt;&lt;P&gt;output: 20130206&lt;/P&gt;&lt;P&gt;=Left(20130206,1,4)&lt;/P&gt;&lt;P&gt;output: 2013&lt;/P&gt;&lt;P&gt;=1&amp;amp;"/"&amp;amp;1&amp;amp;"/"&amp;amp;2013&lt;/P&gt;&lt;P&gt;output: 1/1/2013&lt;/P&gt;&lt;P&gt;=Datevalue(1/1/2013)&lt;/P&gt;&lt;P&gt;Output: 1/1/2013 in date format or 1/1/2012 if subtracting one from the current year.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Route 2: use a SAS function for date shift to calculate at the correct date. In searching the forums I've seen intnx and mdy used in what looks like a similar goal.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Would anyone have an efficient route to pursue? &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;TS&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 07 Jan 2015 14:51:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-Manipulation/m-p/172425#M301620</guid>
      <dc:creator>GalacticAbacus</dc:creator>
      <dc:date>2015-01-07T14:51:17Z</dc:date>
    </item>
    <item>
      <title>Re: Date Manipulation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-Manipulation/m-p/172426#M301621</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Second method will do it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let Start_Date = '06FEB2013:0:0:0'dt;&lt;/P&gt;&lt;P&gt;data _null_;&lt;BR /&gt;prevybeg=intnx('year',datepart(&amp;amp;Start_Date),-1,'b');&lt;BR /&gt;format prevybeg date9.;&lt;BR /&gt;put prevybeg=;&lt;BR /&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 07 Jan 2015 14:56:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-Manipulation/m-p/172426#M301621</guid>
      <dc:creator>Loko</dc:creator>
      <dc:date>2015-01-07T14:56:40Z</dc:date>
    </item>
    <item>
      <title>Re: Date Manipulation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-Manipulation/m-p/172427#M301622</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I agree with you: second method will do the work.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I suggest the following improvement to get the result in datetime format:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let Start_Date = '06FEB2013:0:0:0'dt;&lt;/P&gt;&lt;P&gt;data _null_;&lt;BR /&gt;prevybeg=&lt;STRONG&gt;dhms&lt;/STRONG&gt;(intnx('year',datepart(&amp;amp;Start_Date),-1,'b')&lt;STRONG&gt;,0,0,0)&lt;/STRONG&gt;;&lt;BR /&gt;format prevybeg &lt;STRONG&gt;datetime19&lt;/STRONG&gt;.;&lt;BR /&gt;put prevybeg=;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CTorres&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 07 Jan 2015 15:13:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-Manipulation/m-p/172427#M301622</guid>
      <dc:creator>CTorres</dc:creator>
      <dc:date>2015-01-07T15:13:36Z</dc:date>
    </item>
    <item>
      <title>Re: Date Manipulation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-Manipulation/m-p/172428#M301623</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Personally I don't like macro variables, I tend to store any parameters in datasets and then use them from there.&amp;nbsp; For instance an example.&amp;nbsp; I have some records and I want to flag records with a dt after the default then you could just left join that dataset onto your working data and use date functions.&amp;nbsp; Far easier than messing around with character macro variables.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 07 Jan 2015 15:19:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-Manipulation/m-p/172428#M301623</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2015-01-07T15:19:54Z</dc:date>
    </item>
    <item>
      <title>Re: Date Manipulation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-Manipulation/m-p/172429#M301624</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you, intnx worked well. Was an excellent example.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 07 Jan 2015 15:39:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-Manipulation/m-p/172429#M301624</guid>
      <dc:creator>GalacticAbacus</dc:creator>
      <dc:date>2015-01-07T15:39:35Z</dc:date>
    </item>
  </channel>
</rss>

