BookmarkSubscribeRSS Feed
hwangnyc
Quartz | Level 8

Hi Everyone,

 

I have a list variable that is a list of dates ranging from 2008-2016.  I'd like to recode those dates into biweekly periods. So essentally a variable with 26 categories and if the date falls within that period, it would be recoded as such. 

 

The result would look like this:

 

 

Date        BiweeklyVariable
1/1/20161
1/1/20151
1/30/20162
1/30/20152
2/1/20163
2/1/20163

 

Any help would be greatly appreciated!

 

Thanks

 

1 REPLY 1
ballardw
Super User

The function WEEK will return a week number of a year from a SAS date value.So you could use the Week function and divide by 2 and round to get a biweek value. One thing to consider is when your week count starts. The function has option U, V and W which determine some rules for which "week" a date may be based on how the calendar year starts and whether Sunday or Monday is the first day of the week.

Note that since there are 52.14 weeks in a year (and a bit more in leap years) you can have the last couple days of December actually in week 53.

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!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 1729 views
  • 0 likes
  • 2 in conversation