BookmarkSubscribeRSS Feed
ebonfil89
Calcite | Level 5

Hello,

 

I am in need of some help.

 

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).

 

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.

 

I was told to use the "weekday function", however, I am not sure if this is in a data or proc step.

 

Any help would be appreciated, I am a beginner, and I am using SAS studio. Thank you. 

 

Below is an example data set.

 

ID      wearDate   sed    wearTime (MIN)
281    11/9/14    667    984
282   11/10/14    792    1009
283    11/11/14    674    875
284    11/12/14    785    1029
285    11/13/14    684    909
286    11/14/14    662    878

 

 

 

1 REPLY 1
Reeza
Super User

Functions are used in a data step or PROC SQL, not in other PROCS.  

 

 

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. 

 

1. Create a new variable using the WEEKDAY function to get the weekday

2. Create another new variable that shows if it's a weekend or weekday

 

Why do you need separate data steps? It's unlikely you actually do need a separate data sets.

 

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;

@ebonfil89 wrote:

Hello,

 

I am in need of some help.

 

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).

 

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.

 

I was told to use the "weekday function", however, I am not sure if this is in a data or proc step.

 

Any help would be appreciated, I am a beginner, and I am using SAS studio. Thank you. 

 

Below is an example data set.

 

ID      wearDate   sed    wearTime (MIN)
281    11/9/14    667    984
282   11/10/14    792    1009
283    11/11/14    674    875
284    11/12/14    785    1029
285    11/13/14    684    909
286    11/14/14    662    878

 

 

 


 

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 960 views
  • 0 likes
  • 2 in conversation