BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Rish
Calcite | Level 5

Hello Guru's;

I have a SAS date and want to convert it to week day of the year (for mulitple years).

For example 08JAN2009 show as '2 week of 2009'.

Can anybody please advise?

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

Sorry, I just noticed your code.  You never stipulated a variable for SAS to create.  Try something like:

data xyz;

     set web.pmrate (keep= customer datefield);

     week=week(datefield, 'v');

run;

View solution in original post

5 REPLIES 5
art297
Opal | Level 21

You could use the week function.  i.e.:

WEEK( date <, 'descriptor'> )

returns the week of year from a SAS date value. The algorithm used to calculate the week depends on the descriptor.

If the descriptor is 'U,' weeks start on Sunday and the range is to . If weeks and exist, they are only partial weeks. Week 52 can be a partial week.

If the descriptor is 'V', the result is equivalent to the ISO 8601 week of year definition. The range is to . Week is a leap week. The first week of the year, Week , and the last week of the year, Week or , can include days in another Gregorian calendar year.

If the descriptor is 'W', weeks start on Monday and the range is to . If weeks and exist, they are only partial weeks. Week 52 can be a partial week.

Rish
Calcite | Level 5

Arthur -

Tried to run the below code - giving error. Any advise please.

data xyz;

     set web.pmrate (keep= customer datefield);

     week(datefield, 'v');

run;

Thanks

art297
Opal | Level 21

what version of SAS are you using and what was the error?

Rish
Calcite | Level 5

Hi Arthur,

Following is the information:

SAS 9.2 version 4.3

error: undeclared array referenced; week.

error 22-322: syntax error, expecting one of the following: +, =.

error 76-322: syntax error, statement will be ignored.

Thanks       

art297
Opal | Level 21

Sorry, I just noticed your code.  You never stipulated a variable for SAS to create.  Try something like:

data xyz;

     set web.pmrate (keep= customer datefield);

     week=week(datefield, 'v');

run;

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
  • 5 replies
  • 6917 views
  • 1 like
  • 2 in conversation