<?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 with day of the week in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/date-with-day-of-the-week/m-p/896715#M354334</link>
    <description>&lt;P&gt;I have a date var and I'm trying to create a new var with a format like: 10/02/2023 Mon.&amp;nbsp; I thought the following would work, but the format for the vars are not kept in the new var.&amp;nbsp; Concatenating the vars keeps the original numeric format.&amp;nbsp;&lt;/P&gt;&lt;P&gt;RECEIVE_DT=DATEPART(SPECIMEN_RECV_TIME);&lt;BR /&gt;FORMAT RECEIVE_DT MMDDYY10.;&lt;BR /&gt;DAYOFWEEK=WEEKDAY(RECEIVE_DT);&lt;BR /&gt;FORMAT DAYOFWEEK WEEKDATE3.;&lt;BR /&gt;REC_DT=RECEIVE_DT||DAYOFWEEK;&lt;/P&gt;</description>
    <pubDate>Mon, 02 Oct 2023 16:37:28 GMT</pubDate>
    <dc:creator>swioak</dc:creator>
    <dc:date>2023-10-02T16:37:28Z</dc:date>
    <item>
      <title>date with day of the week</title>
      <link>https://communities.sas.com/t5/SAS-Programming/date-with-day-of-the-week/m-p/896715#M354334</link>
      <description>&lt;P&gt;I have a date var and I'm trying to create a new var with a format like: 10/02/2023 Mon.&amp;nbsp; I thought the following would work, but the format for the vars are not kept in the new var.&amp;nbsp; Concatenating the vars keeps the original numeric format.&amp;nbsp;&lt;/P&gt;&lt;P&gt;RECEIVE_DT=DATEPART(SPECIMEN_RECV_TIME);&lt;BR /&gt;FORMAT RECEIVE_DT MMDDYY10.;&lt;BR /&gt;DAYOFWEEK=WEEKDAY(RECEIVE_DT);&lt;BR /&gt;FORMAT DAYOFWEEK WEEKDATE3.;&lt;BR /&gt;REC_DT=RECEIVE_DT||DAYOFWEEK;&lt;/P&gt;</description>
      <pubDate>Mon, 02 Oct 2023 16:37:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/date-with-day-of-the-week/m-p/896715#M354334</guid>
      <dc:creator>swioak</dc:creator>
      <dc:date>2023-10-02T16:37:28Z</dc:date>
    </item>
    <item>
      <title>Re: date with day of the week</title>
      <link>https://communities.sas.com/t5/SAS-Programming/date-with-day-of-the-week/m-p/896719#M354335</link>
      <description>&lt;P&gt;Please show us:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;A typical value of this variable&amp;nbsp;&lt;SPAN&gt;SPECIMEN_RECV_TIME as seen in PROC PRINT or viewing it in SAS.&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI&gt;PROC CONTENTS output about your date variable named&amp;nbsp;&lt;SPAN&gt;SPECIMEN_RECV_TIME.&lt;/SPAN&gt;&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;That's the only way we can really know what what type of variable this is and how it is formatted.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 02 Oct 2023 16:57:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/date-with-day-of-the-week/m-p/896719#M354335</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-10-02T16:57:33Z</dc:date>
    </item>
    <item>
      <title>Re: date with day of the week</title>
      <link>https://communities.sas.com/t5/SAS-Programming/date-with-day-of-the-week/m-p/896739#M354340</link>
      <description>&lt;P&gt;Let's parse your data manipulation:&lt;/P&gt;
&lt;P&gt;DAYOFWEEK=WEEKDAY(RECEIVE_DT);&lt;/P&gt;
&lt;P&gt;The Weekday function from the online help:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;DIV class="xis-refDictEntry"&gt;
&lt;DIV class="xis-details"&gt;
&lt;H2 id="p0oebnw853f0w0n1bwuyq02pjhc0" class="xis-title"&gt;Details&lt;/H2&gt;
&lt;DIV id="n0rhd0odxny55jn17o5mndcw2zz1" class="xis-topicContent"&gt;
&lt;DIV id="n1n6j6jqoydh0kn1suc9mqqdue3l" class="xis-paragraph"&gt;The &lt;FONT style="background-color: #fcdec0;"&gt;WEEKDAY&lt;/FONT&gt; function produces an integer that represents the day of the week, where 1=Sunday, 2=Monday, ..., 7=Saturday.&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Dates are the number of days from 1 Jan 1960. So you apply a format that expects numeric values from about -138061 to&amp;nbsp; 6588970 to a value that only is 1 to 7. So when apply a date format to the value then SAS thinks you want the date from 01JAN1960 to 07Jan1960. Which are very likely not to match the days of the week for about 6 of 7 days of the week.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How about showing what you actually want to display? It may be easier to create a custom format than to write fragile code and manipulate values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This shows an example of creating a format to use with datetime values directly to create mm/yy/dd with a 3 letter abbreviation of the day of the week and another to use a date value.&lt;/P&gt;
&lt;PRE&gt;proc format;
picture mydatetime_dow
low-high ='%0m/%0d/%Y %3a' (datatype=datetime);
picture mymmddyy_dow
low-high ='%0m/%0d/%Y %3a' (datatype=date);
run;

data example;
   x= dhms(today(),0,0,time());
   put x= mydatetime_dow.;  
   y=today();
   put y= mymmddyy_dow.;
run;&lt;/PRE&gt;</description>
      <pubDate>Mon, 02 Oct 2023 17:56:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/date-with-day-of-the-week/m-p/896739#M354340</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-10-02T17:56:59Z</dc:date>
    </item>
    <item>
      <title>Re: date with day of the week</title>
      <link>https://communities.sas.com/t5/SAS-Programming/date-with-day-of-the-week/m-p/896740#M354341</link>
      <description>&lt;P&gt;My new var, REC_DT became a character var.&amp;nbsp; I'd like to format this variable as 10/02/2013 Mon or 10/02/2023 (Mon)&lt;/P&gt;</description>
      <pubDate>Mon, 02 Oct 2023 17:51:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/date-with-day-of-the-week/m-p/896740#M354341</guid>
      <dc:creator>swioak</dc:creator>
      <dc:date>2023-10-02T17:51:01Z</dc:date>
    </item>
    <item>
      <title>Re: date with day of the week</title>
      <link>https://communities.sas.com/t5/SAS-Programming/date-with-day-of-the-week/m-p/896745#M354343</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How about showing what you actually want to display? It may be easier to create a custom format than to write fragile code and manipulate values.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Agreeing with&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;, are not the built-in formats sufficient, wouldn't it be acceptable and equally understandable to use the DTWKDATX format or the WEEKDATX format, which produce dates like this:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Wednesday&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;28&lt;/SPAN&gt;&lt;SPAN&gt; March &lt;/SPAN&gt;&lt;SPAN class="token number"&gt;2018&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 02 Oct 2023 17:55:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/date-with-day-of-the-week/m-p/896745#M354343</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-10-02T17:55:50Z</dc:date>
    </item>
    <item>
      <title>Re: date with day of the week</title>
      <link>https://communities.sas.com/t5/SAS-Programming/date-with-day-of-the-week/m-p/896749#M354344</link>
      <description>&lt;P&gt;Yes, the&amp;nbsp;&lt;SPAN&gt;WEEKDATX. format would work, but I'm trying to customize my date/day of the week format to look like:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;10/02/2023 Mon or 10/02/2023 (Mon)&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 02 Oct 2023 18:02:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/date-with-day-of-the-week/m-p/896749#M354344</guid>
      <dc:creator>swioak</dc:creator>
      <dc:date>2023-10-02T18:02:13Z</dc:date>
    </item>
    <item>
      <title>Re: date with day of the week</title>
      <link>https://communities.sas.com/t5/SAS-Programming/date-with-day-of-the-week/m-p/896782#M354356</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10030"&gt;@swioak&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Yes, the&amp;nbsp;&lt;SPAN&gt;WEEKDATX. format would work, but I'm trying to customize my date/day of the week format to look like:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;10/02/2023 Mon or 10/02/2023 (Mon)&lt;/SPAN&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Run the Proc Format code in my previous post.&lt;/P&gt;
&lt;P&gt;Use the MYdatetime_dow format with your datetime variable. No need to create anything.&lt;/P&gt;
&lt;P&gt;If you really want () around the day of the week place the ( ) around the %3a in the format picture statement. WARNING: These directives in the picture statement are case sensitive. %a is abbreviated day of week (defaults to 2 characters, the %3a says use 3 characters), %A is the full name of the weekday. Mix up %m and %M and you can end up with minutes instead of months. The zeroes mean that single digit month or day values will appear in the format with a leading zero&amp;nbsp; 09/03/2023 for Sep 3 2023.&lt;/P&gt;</description>
      <pubDate>Mon, 02 Oct 2023 19:38:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/date-with-day-of-the-week/m-p/896782#M354356</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-10-02T19:38:14Z</dc:date>
    </item>
    <item>
      <title>Re: date with day of the week</title>
      <link>https://communities.sas.com/t5/SAS-Programming/date-with-day-of-the-week/m-p/896827#M354377</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10030"&gt;@swioak&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Yes, the&amp;nbsp;&lt;SPAN&gt;WEEKDATX. format would work, but I'm trying to customize my date/day of the week format to look like:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;10/02/2023 Mon or 10/02/2023 (Mon)&lt;/SPAN&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Great, but you did not provide the two pieces of information which I asked for earlier. Until we have that information, we cannot give definitive answers.&lt;/P&gt;</description>
      <pubDate>Mon, 02 Oct 2023 21:46:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/date-with-day-of-the-week/m-p/896827#M354377</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-10-02T21:46:57Z</dc:date>
    </item>
    <item>
      <title>Re: date with day of the week</title>
      <link>https://communities.sas.com/t5/SAS-Programming/date-with-day-of-the-week/m-p/896833#M354381</link>
      <description>&lt;P&gt;My apologies.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;specimen_recv_time as from proc print&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="swioak_0-1696285771007.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/88507i991E3FC562AC91CE/image-size/medium?v=v2&amp;amp;px=400" role="button" title="swioak_0-1696285771007.png" alt="swioak_0-1696285771007.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;from proc contents:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="swioak_1-1696285850691.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/88508i334DBB7456B1F96F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="swioak_1-1696285850691.png" alt="swioak_1-1696285850691.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 02 Oct 2023 22:31:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/date-with-day-of-the-week/m-p/896833#M354381</guid>
      <dc:creator>swioak</dc:creator>
      <dc:date>2023-10-02T22:31:02Z</dc:date>
    </item>
    <item>
      <title>Re: date with day of the week</title>
      <link>https://communities.sas.com/t5/SAS-Programming/date-with-day-of-the-week/m-p/896837#M354385</link>
      <description>&lt;P&gt;So your variable does not contain DATE values.&amp;nbsp; It has DATETIME values.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  length string $16 ;
  string=catx(' ',put(datepart(specimen_recv_time),mmddyy10.)
        ,cats('(',put(datepart(specimen_recv_time),downame3.),')')
        )
  ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;Obs     specimen_recv_time         string

 1      02OCT2023:20:11:03    10/02/2023 (Mon)

&lt;/PRE&gt;
&lt;P&gt;PS Displaying dates in MDY order will confuse 50% of your audience, plus the strings will not sort in chronological order.&amp;nbsp; Better to use YMD order.&amp;nbsp; Plus you can generate a date string in YMD order directly from a datetime value.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  string=catx(' ',put(specimen_recv_time,e8601dn10.)
        ,cats('(',put(datepart(specimen_recv_time),downame3.),')')
        )
  ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;Obs     specimen_recv_time         string

 1      02OCT2023:20:15:31    2023-10-02 (Mon)
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 03 Oct 2023 00:16:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/date-with-day-of-the-week/m-p/896837#M354385</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-10-03T00:16:39Z</dc:date>
    </item>
    <item>
      <title>Re: date with day of the week</title>
      <link>https://communities.sas.com/t5/SAS-Programming/date-with-day-of-the-week/m-p/896841#M354387</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;already provided a working solution "long ago". What prevents you from using it?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
  picture mydatetime_dow
    low-high ='%0m/%0d/%Y %3a' (datatype=datetime)
    ;
run;

data example;
  specimen_recv_time=datetime();
  specimen_recv_time_2=datetime();
  format specimen_recv_time_2 mydatetime_dow.;
run;

proc print data=example;
  format specimen_recv_time mydatetime_dow.;
run;

proc contents data=example;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1696298606111.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/88509i674A27796597A436/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_0-1696298606111.png" alt="Patrick_0-1696298606111.png" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_1-1696298628961.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/88510iFEC5DDCF8BD1900C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_1-1696298628961.png" alt="Patrick_1-1696298628961.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 03 Oct 2023 02:03:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/date-with-day-of-the-week/m-p/896841#M354387</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2023-10-03T02:03:55Z</dc:date>
    </item>
  </channel>
</rss>

