<?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 How to sort by date and create two new data sets. in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/How-to-sort-by-date-and-create-two-new-data-sets/m-p/439531#M69142</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am in need of some help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a data set that that contains 7000 observations and one of the variables is wear-date. Wear date specifies the date the data was recorded. The format for wear date is (i.g. 11/9/2014).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to create two data sets from one main data set. One for weekday observations and one for weekend observations. Therefore I need to sort dates by weekday and weekends.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I was told to use the "weekday function", however, I am not sure if this is in a data or proc step.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help would be appreciated, I am a beginner, and I am using SAS studio. Thank you.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below is an example data set.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; wearDate&amp;nbsp;&amp;nbsp; sed&amp;nbsp;&amp;nbsp; &amp;nbsp;wearTime (MIN)&lt;BR /&gt;281 &amp;nbsp;&amp;nbsp; 11/9/14&amp;nbsp;&amp;nbsp; &amp;nbsp;667&amp;nbsp;&amp;nbsp; &amp;nbsp;984&lt;BR /&gt;282 &amp;nbsp; 11/10/14&amp;nbsp;&amp;nbsp; &amp;nbsp;792&amp;nbsp;&amp;nbsp; &amp;nbsp;1009&lt;BR /&gt;283 &amp;nbsp;&amp;nbsp; 11/11/14&amp;nbsp;&amp;nbsp; &amp;nbsp;674&amp;nbsp;&amp;nbsp; &amp;nbsp;875&lt;BR /&gt;284 &amp;nbsp;&amp;nbsp; 11/12/14&amp;nbsp;&amp;nbsp; &amp;nbsp;785&amp;nbsp;&amp;nbsp; &amp;nbsp;1029&lt;BR /&gt;285 &amp;nbsp;&amp;nbsp; 11/13/14&amp;nbsp;&amp;nbsp; &amp;nbsp;684&amp;nbsp;&amp;nbsp; &amp;nbsp;909&lt;BR /&gt;286 &amp;nbsp;&amp;nbsp; 11/14/14&amp;nbsp;&amp;nbsp; &amp;nbsp;662&amp;nbsp;&amp;nbsp; &amp;nbsp;878&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 23 Feb 2018 00:45:35 GMT</pubDate>
    <dc:creator>ebonfil89</dc:creator>
    <dc:date>2018-02-23T00:45:35Z</dc:date>
    <item>
      <title>How to sort by date and create two new data sets.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-sort-by-date-and-create-two-new-data-sets/m-p/439531#M69142</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am in need of some help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a data set that that contains 7000 observations and one of the variables is wear-date. Wear date specifies the date the data was recorded. The format for wear date is (i.g. 11/9/2014).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to create two data sets from one main data set. One for weekday observations and one for weekend observations. Therefore I need to sort dates by weekday and weekends.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I was told to use the "weekday function", however, I am not sure if this is in a data or proc step.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help would be appreciated, I am a beginner, and I am using SAS studio. Thank you.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below is an example data set.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; wearDate&amp;nbsp;&amp;nbsp; sed&amp;nbsp;&amp;nbsp; &amp;nbsp;wearTime (MIN)&lt;BR /&gt;281 &amp;nbsp;&amp;nbsp; 11/9/14&amp;nbsp;&amp;nbsp; &amp;nbsp;667&amp;nbsp;&amp;nbsp; &amp;nbsp;984&lt;BR /&gt;282 &amp;nbsp; 11/10/14&amp;nbsp;&amp;nbsp; &amp;nbsp;792&amp;nbsp;&amp;nbsp; &amp;nbsp;1009&lt;BR /&gt;283 &amp;nbsp;&amp;nbsp; 11/11/14&amp;nbsp;&amp;nbsp; &amp;nbsp;674&amp;nbsp;&amp;nbsp; &amp;nbsp;875&lt;BR /&gt;284 &amp;nbsp;&amp;nbsp; 11/12/14&amp;nbsp;&amp;nbsp; &amp;nbsp;785&amp;nbsp;&amp;nbsp; &amp;nbsp;1029&lt;BR /&gt;285 &amp;nbsp;&amp;nbsp; 11/13/14&amp;nbsp;&amp;nbsp; &amp;nbsp;684&amp;nbsp;&amp;nbsp; &amp;nbsp;909&lt;BR /&gt;286 &amp;nbsp;&amp;nbsp; 11/14/14&amp;nbsp;&amp;nbsp; &amp;nbsp;662&amp;nbsp;&amp;nbsp; &amp;nbsp;878&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Feb 2018 00:45:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-sort-by-date-and-create-two-new-data-sets/m-p/439531#M69142</guid>
      <dc:creator>ebonfil89</dc:creator>
      <dc:date>2018-02-23T00:45:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to sort by date and create two new data sets.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-sort-by-date-and-create-two-new-data-sets/m-p/439545#M69143</link>
      <description>&lt;P&gt;Functions are used in a data step or PROC SQL, not in other PROCS. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you review the documentation for WEEKDAY() it returns 1-7, with 1/7 being weekends so you can classify your dates. Then you can separate them. I'm not sure why you need to sort.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. Create a new variable using the WEEKDAY function to get the weekday&lt;/P&gt;
&lt;P&gt;2. Create another new variable that shows if it's a weekend or weekday&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why do you need separate data steps? It's unlikely you actually do need a separate data sets.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data identify_weekday;

set have; *this should be your input data set;

weekDayNumber = weekday(date); *get weekday;

If weekDayNumber in (1, 7) then weekDayType='Weekend';
else if weekDayNumber in (2:6) then weekDayType='Weekday';
else weekDayType='CHECKME';

run;

*Check coding is correct;
proc freq data=identify_weekday;
table weekDayType*weedDayNumber;
run;

*See summaries by weekdayType;
proc means data=identify_weekday;
class weekDayType;
var wearTime;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/194026"&gt;@ebonfil89&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am in need of some help.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a data set that that contains 7000 observations and one of the variables is wear-date. Wear date specifies the date the data was recorded. The format for wear date is (i.g. 11/9/2014).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to create two data sets from one main data set. One for weekday observations and one for weekend observations. Therefore I need to sort dates by weekday and weekends.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I was told to use the "weekday function", however, I am not sure if this is in a data or proc step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any help would be appreciated, I am a beginner, and I am using SAS studio. Thank you.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Below is an example data set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ID &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; wearDate&amp;nbsp;&amp;nbsp; sed&amp;nbsp;&amp;nbsp; &amp;nbsp;wearTime (MIN)&lt;BR /&gt;281 &amp;nbsp;&amp;nbsp; 11/9/14&amp;nbsp;&amp;nbsp; &amp;nbsp;667&amp;nbsp;&amp;nbsp; &amp;nbsp;984&lt;BR /&gt;282 &amp;nbsp; 11/10/14&amp;nbsp;&amp;nbsp; &amp;nbsp;792&amp;nbsp;&amp;nbsp; &amp;nbsp;1009&lt;BR /&gt;283 &amp;nbsp;&amp;nbsp; 11/11/14&amp;nbsp;&amp;nbsp; &amp;nbsp;674&amp;nbsp;&amp;nbsp; &amp;nbsp;875&lt;BR /&gt;284 &amp;nbsp;&amp;nbsp; 11/12/14&amp;nbsp;&amp;nbsp; &amp;nbsp;785&amp;nbsp;&amp;nbsp; &amp;nbsp;1029&lt;BR /&gt;285 &amp;nbsp;&amp;nbsp; 11/13/14&amp;nbsp;&amp;nbsp; &amp;nbsp;684&amp;nbsp;&amp;nbsp; &amp;nbsp;909&lt;BR /&gt;286 &amp;nbsp;&amp;nbsp; 11/14/14&amp;nbsp;&amp;nbsp; &amp;nbsp;662&amp;nbsp;&amp;nbsp; &amp;nbsp;878&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Feb 2018 01:09:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-sort-by-date-and-create-two-new-data-sets/m-p/439545#M69143</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-02-23T01:09:54Z</dc:date>
    </item>
  </channel>
</rss>

