<?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: How to create a weekday/weekend indicator variable based on date? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-weekday-weekend-indicator-variable-based-on-date/m-p/957430#M373759</link>
    <description>&lt;P&gt;Comma is not part of the syntax of the IF statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Perhaps you are of the mistaken believe you have to use commas only as the delimiter in the list of values of the right hand argument of the IN operator?&amp;nbsp; That is NOT true in SAS syntax.&amp;nbsp; You can use comma or space as a delimiter in the list.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also notice the use of the : to indicate a RANGE of integer values in the right hand argument of the IN operator.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So this code would also work fine:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if weekday(date_of_injury) in (2,3 4:5 6) then weekend=0;
else weekend=1;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 28 Jan 2025 03:19:30 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2025-01-28T03:19:30Z</dc:date>
    <item>
      <title>How to create a weekday/weekend indicator variable based on date?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-weekday-weekend-indicator-variable-based-on-date/m-p/950787#M371759</link>
      <description>&lt;P&gt;As the subject says, I'm trying to figure out how to create a weekend/weekday indicator variable based on date.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have found the weekday. format where Sunday =1, Monday =2, etc. and am trying to use a statement in a datastep such as:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;If (weekday format of my date) in (1 7) then weekend = 1;

ELSE IF (weekday format of my date) in (2:6) then weekend = 0;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm having trouble figuring out how to indicate (weekday format of my date).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for your help!&lt;/P&gt;</description>
      <pubDate>Thu, 14 Nov 2024 15:00:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-weekday-weekend-indicator-variable-based-on-date/m-p/950787#M371759</guid>
      <dc:creator>sasgorilla</dc:creator>
      <dc:date>2024-11-14T15:00:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a weekday/weekend indicator variable based on date?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-weekday-weekend-indicator-variable-based-on-date/m-p/950791#M371760</link>
      <description>&lt;P&gt;Instead of looking at the weekday format, look at the weekday function.&amp;nbsp; It can easily be plugged into your existing code.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Nov 2024 15:15:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-weekday-weekend-indicator-variable-based-on-date/m-p/950791#M371760</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2024-11-14T15:15:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a weekday/weekend indicator variable based on date?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-weekday-weekend-indicator-variable-based-on-date/m-p/950794#M371762</link>
      <description>&lt;P&gt;Thank you! The function did the trick.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;IF weekday(date_of_Injury) in (1 7) then weekend=1;
	ELSE IF weekday(date_of_Injury) in (2:6) then weekend=0;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Nov 2024 15:28:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-weekday-weekend-indicator-variable-based-on-date/m-p/950794#M371762</guid>
      <dc:creator>sasgorilla</dc:creator>
      <dc:date>2024-11-14T15:28:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a weekday/weekend indicator variable based on date?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-weekday-weekend-indicator-variable-based-on-date/m-p/957408#M373751</link>
      <description>&lt;P&gt;Hi sasgorilla, I found some of your posts rather interesting. I tested your code, weekday() is the right function to use, however, there is a tiny syntax error: you missed a comma in the if statement. I corrected it and my version of code and output are as follows (I also created a small dataset to test the code).&lt;/P&gt;&lt;P&gt;data test;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;input subjid date_of_injury date9.;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;format date_of_injury date9.;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;datalines;&lt;BR /&gt;1 01dec2024&lt;BR /&gt;2 02dec2024&lt;BR /&gt;3 07dec2024&lt;BR /&gt;4 08dec2024&lt;BR /&gt;5 09dec2024&lt;BR /&gt;6 10dec2024&lt;BR /&gt;7 14dec2024&lt;BR /&gt;8 15dec2024&lt;BR /&gt;9 16dec2024&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;data test1;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;set test;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;weekday=weekday(date_of_injury);&lt;BR /&gt;&amp;nbsp; &amp;nbsp;if weekday(date_of_injury) in (1,7) then weekend=1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; else weekend=0;&lt;BR /&gt;run;&lt;BR /&gt;proc print data=test1;run;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Untitled5.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/104058iE8650097C60A6433/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Untitled5.png" alt="Untitled5.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;</description>
      <pubDate>Tue, 28 Jan 2025 00:30:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-weekday-weekend-indicator-variable-based-on-date/m-p/957408#M373751</guid>
      <dc:creator>dxiao2017</dc:creator>
      <dc:date>2025-01-28T00:30:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a weekday/weekend indicator variable based on date?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-weekday-weekend-indicator-variable-based-on-date/m-p/957430#M373759</link>
      <description>&lt;P&gt;Comma is not part of the syntax of the IF statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Perhaps you are of the mistaken believe you have to use commas only as the delimiter in the list of values of the right hand argument of the IN operator?&amp;nbsp; That is NOT true in SAS syntax.&amp;nbsp; You can use comma or space as a delimiter in the list.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also notice the use of the : to indicate a RANGE of integer values in the right hand argument of the IN operator.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So this code would also work fine:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if weekday(date_of_injury) in (2,3 4:5 6) then weekend=0;
else weekend=1;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jan 2025 03:19:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-weekday-weekend-indicator-variable-based-on-date/m-p/957430#M373759</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-01-28T03:19:30Z</dc:date>
    </item>
  </channel>
</rss>

