<?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: Date format in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Date-format/m-p/933419#M367102</link>
    <description>&lt;P&gt;And here's a code example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
picture mmdd
  low-high = '%0m-%0d' (datatype=datetime)
;
run;

data want;
now = datetime();
year_week = compress(put(datepart(now),yyweekv8.),"W");
month_day = put(now,mmdd.);
format now datetime19.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 22 Jun 2024 14:03:36 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2024-06-22T14:03:36Z</dc:date>
    <item>
      <title>Date format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-format/m-p/933407#M367094</link>
      <description>&lt;P&gt;Hello Experts,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My code is :&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;AnneeSemaine=compress(year(datepart (MaDate))||"-"||week(datepart(MaDate),'v'));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I have the value&amp;nbsp;2023-9, do you know please some easy option to get&amp;nbsp;2023-09?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My second line of code is :&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Moisjour=compress(month(datepart (MaDate))||"-"||day(datepart(MaDate))); &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I have the value 9-2, do you know please how to get the value&amp;nbsp;09-02 ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for your help !&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 22 Jun 2024 10:23:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-format/m-p/933407#M367094</guid>
      <dc:creator>SASdevAnneMarie</dc:creator>
      <dc:date>2024-06-22T10:23:28Z</dc:date>
    </item>
    <item>
      <title>Re: Date format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-format/m-p/933415#M367098</link>
      <description>&lt;P&gt;For the first, use the&amp;nbsp;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/leforinforref/p0on7fye8sv4kpn13vp1wdbn11ix.htm" target="_blank" rel="noopener"&gt;YYWEEKV&lt;/A&gt;&amp;nbsp;format, and either (with a format length of 7) replace the W with a dash, or (with a length of &lt;span class="lia-unicode-emoji" title=":smiling_face_with_sunglasses:"&gt;😎&lt;/span&gt; COMPRESS the W away.&lt;/P&gt;
&lt;P&gt;For the second, roll your own formt with PROC FORMAT. Specify a DATATYPE of datetime, so you can even omit the DATEPART function.&lt;/P&gt;</description>
      <pubDate>Sat, 22 Jun 2024 13:32:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-format/m-p/933415#M367098</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-06-22T13:32:32Z</dc:date>
    </item>
    <item>
      <title>Re: Date format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-format/m-p/933416#M367099</link>
      <description>&lt;P&gt;First use one of the new CAT series of functions so you don't need COMPRESS().&lt;/P&gt;
&lt;P&gt;Second take control over how the number is converted to a string before the concatenation.&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;AnneeSemaine=catx('-',put(datepart(MaDate),year4.),put(week(datepart(MaDate),'V'),Z2.));
Moisjour=catx('-',put(month(datepart(MaDate)),Z2.),put(day(datepart(MaDate)),Z2.)); &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or just use the right FORMAT to generate the string directly from the DATE value.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;AnneeSemaine=compress(put(datepart(MaDate),yyweekv8.),'W');
Moisjour=substr(put(datepart(MaDate),yymmddd10.),6);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 22 Jun 2024 13:41:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-format/m-p/933416#M367099</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-06-22T13:41:21Z</dc:date>
    </item>
    <item>
      <title>Re: Date format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-format/m-p/933419#M367102</link>
      <description>&lt;P&gt;And here's a code example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
picture mmdd
  low-high = '%0m-%0d' (datatype=datetime)
;
run;

data want;
now = datetime();
year_week = compress(put(datepart(now),yyweekv8.),"W");
month_day = put(now,mmdd.);
format now datetime19.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 22 Jun 2024 14:03:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-format/m-p/933419#M367102</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-06-22T14:03:36Z</dc:date>
    </item>
    <item>
      <title>Re: Date format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-format/m-p/933435#M367112</link>
      <description>&lt;P&gt;The same idea with Kurt.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
picture mmdd
  low-high = '%0Y-%0V' (datatype=datetime)
;

picture mm
  low-high = '%0Y-%0W' (datatype=datetime)
;

picture m
  low-high = '%0Y-%0U' (datatype=datetime)
;
run;

data want;
now = datetime();
format now mmdd7.;

_now ='01jan2024:10:01:10'dt;
format _now mm7.;

_now2 ='01jan2024:10:01:10'dt;
format _now2 m7.;
run;

proc print;run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 23 Jun 2024 00:51:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-format/m-p/933435#M367112</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2024-06-23T00:51:09Z</dc:date>
    </item>
    <item>
      <title>Re: Date format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-format/m-p/933458#M367126</link>
      <description>Thank you, Tom !</description>
      <pubDate>Sun, 23 Jun 2024 10:58:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-format/m-p/933458#M367126</guid>
      <dc:creator>SASdevAnneMarie</dc:creator>
      <dc:date>2024-06-23T10:58:33Z</dc:date>
    </item>
  </channel>
</rss>

