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 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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