<?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: put date into string in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/put-date-into-string/m-p/160848#M31300</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you Tom.&amp;nbsp; I've been using SAS off and on for well over a year now, and I still find dates to be the most frustrating thing of all. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Greg&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 03 Feb 2014 17:44:37 GMT</pubDate>
    <dc:creator>gsnidow</dc:creator>
    <dc:date>2014-02-03T17:44:37Z</dc:date>
    <item>
      <title>put date into string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/put-date-into-string/m-p/160844#M31296</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Greetings all.&amp;nbsp; I'm having some trouble creating a string variable in format 'YYYY-MM-DD' given an ending date.&amp;nbsp; I would like to supply an end date, then use symput (or whatever else works) to create the begin date.&amp;nbsp; Given dt_end = '2014-02-03', I would like dt_begin to be '2014-01-27', one week earlier, but it is ending up being '19750'.&amp;nbsp; Here is what I am trying...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let dt_end = '2014-02-03' ;&lt;/P&gt;&lt;P&gt;data _null_ ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; call symput('dt_begin', cat("'",input(&amp;amp;dt_end, yymmdd10.)-7,"'"));&lt;/P&gt;&lt;P&gt;run ; quit ;&lt;/P&gt;&lt;P&gt;%put &amp;amp;dt_begin ;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I will be passing these variables into an ODBC query, so I need the single quotes on them.&amp;nbsp; I can't understand why &amp;amp;dt_begin is in date serial format, and not YYYY-MM-DD format.&amp;nbsp; Does anyone have any ideas?&amp;nbsp; Thank you.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Greg&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 03 Feb 2014 17:19:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/put-date-into-string/m-p/160844#M31296</guid>
      <dc:creator>gsnidow</dc:creator>
      <dc:date>2014-02-03T17:19:01Z</dc:date>
    </item>
    <item>
      <title>Re: put date into string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/put-date-into-string/m-p/160845#M31297</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;%let dt_end = '2014-02-03' ;&lt;/P&gt;&lt;P&gt;data _null_ ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; call symput('dt_begin', cat("'",put(input(&amp;amp;dt_end, yymmdd10.),yymmddd10.),"'"));&lt;/P&gt;&lt;P&gt;run ; quit ;&lt;/P&gt;&lt;P&gt;%put &amp;amp;dt_begin ;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 03 Feb 2014 17:29:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/put-date-into-string/m-p/160845#M31297</guid>
      <dc:creator>DBailey</dc:creator>
      <dc:date>2014-02-03T17:29:34Z</dc:date>
    </item>
    <item>
      <title>Re: put date into string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/put-date-into-string/m-p/160846#M31298</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;DBailey, thank you so much.&amp;nbsp; If I'm telling the symput function that I want &amp;amp;dt_end to be in yymmdd10 format, why must I also tell it that I want the result to be in yymmdd10.?&amp;nbsp; That seems kind of redundant.&amp;nbsp; Anyhow, thanks again.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Greg&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 03 Feb 2014 17:32:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/put-date-into-string/m-p/160846#M31298</guid>
      <dc:creator>gsnidow</dc:creator>
      <dc:date>2014-02-03T17:32:41Z</dc:date>
    </item>
    <item>
      <title>Re: put date into string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/put-date-into-string/m-p/160847#M31299</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The INPUT() function is a general tool for converting strings into values.&amp;nbsp; To know what type of conversion you need to provide it an INFORMAT so that it knows what type of conversion to perform.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Dates are stored as number of days since 1/1/1960.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The PUT() function is a general tool for converting a value into a string.&amp;nbsp; To know what type of conversion you need to provide it with a FORMAT.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 03 Feb 2014 17:40:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/put-date-into-string/m-p/160847#M31299</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2014-02-03T17:40:43Z</dc:date>
    </item>
    <item>
      <title>Re: put date into string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/put-date-into-string/m-p/160848#M31300</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you Tom.&amp;nbsp; I've been using SAS off and on for well over a year now, and I still find dates to be the most frustrating thing of all. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Greg&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 03 Feb 2014 17:44:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/put-date-into-string/m-p/160848#M31300</guid>
      <dc:creator>gsnidow</dc:creator>
      <dc:date>2014-02-03T17:44:37Z</dc:date>
    </item>
    <item>
      <title>Re: put date into string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/put-date-into-string/m-p/160849#M31301</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;did you not notice you have to use the INPUT() function to convert your start date before subtracting 7 days?&lt;/P&gt;&lt;P&gt;Your result is a standard SAS-date (a number of days since 1-Jan-1960).&lt;/P&gt;&lt;P&gt;So you need to convert that with the PUT() function in a similar way.&lt;/P&gt;&lt;P&gt;Alternatively, work with SAS-date constants and convert to the DBMS format at the last stage (if you really need it even then)&lt;/P&gt;&lt;P&gt;SAS-date constants are a lot more understandable for us than tHat "number of days since 1960) &lt;img id="smileywink" class="emoticon emoticon-smileywink" src="https://communities.sas.com/i/smilies/16x16_smiley-wink.png" alt="Smiley Wink" title="Smiley Wink" /&gt;&lt;/P&gt;&lt;P&gt;There are hundreds of formats an informats to handle dates.There are also two really helpful functions for date arithmetic &lt;/P&gt;&lt;OL&gt;&lt;LI&gt;INTCK() calculates the number of date/time intervals between two dates (and/or times)&lt;/LI&gt;&lt;LI&gt;INTNX() returns the next date/time after +/- N intervals&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;WEEK is one of those intervals although your question doesn't need more than a 7-day interval, i.e. old-date+/- 7&lt;/P&gt;&lt;P&gt;There are aspects to interval handling you might find very useful (although you dfon't need to go there for this issue)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Your date style is very similar to the style of Teradata dates so I guess you seek the constant to use in that (dbms) kind of context. &lt;/P&gt;&lt;P&gt;With implicit pass-thru SQL you can just use SAS-date constants, but generating a query for the DBMS environment I guess you might need that style for dates. Here is hou you could work&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let today = %sysfunc( today(), date9. ) ;&lt;/P&gt;&lt;P&gt;%let dt_end = %str(%')%sysfunc( putn( "&amp;amp;today"d, yymmddD10.))%str(%') ;&lt;/P&gt;&lt;P&gt;%let dt_begin = %str(%')%sysfunc( intnx( week, "&amp;amp;today"d,&amp;nbsp; -1 , same),yymmddD10.)%str(%') ;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 03 Feb 2014 17:47:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/put-date-into-string/m-p/160849#M31301</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2014-02-03T17:47:11Z</dc:date>
    </item>
  </channel>
</rss>

