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

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

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

View all other training opportunities.

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