Desktop productivity for business analysts and programmers

how to transfer date to week of year

Reply
New Contributor
Posts: 3

how to transfer date to week of year

Hi guys,

I'm faced a problem when trying to transfer specific date data into "week of year". SAS guidance tells me to use "right click the column--properties--formats--WEEK...". I did accordingly, but the result just shows "****", as the right column in the picture.

 

can anyone help with this? what is the right way to sovle it?

 

thank you!

Kira

 

 

Grand Advisor
Posts: 17,355

Re: how to transfer date to week of year

That would only change the format for the current display, it wouldn't be saved in any manner.

 

I would suggest creating a new variable and use the WEEK() function.

 

Use a computed column and advanced expression.

 

WEEK(DateVariable, U/W/V).

 

Check which of the U/W/V options you want when calculating WEEK from a date as there are several different methodologies.

 

http://support.sas.com/documentation/cdl/en/lefunctionsref/69762/HTML/default/viewer.htm#n1ka2ulrvrj...

Grand Advisor
Posts: 10,211

Re: how to transfer date to week of year

When manipulating dates first make sure that your original values are SAS date values. A number like 11052016 is not necessarily a date value. If the current display format says the value is $ (character), BEST or F then the value is not likely to actually be the "date"  you may think.

If you have a numeric value such as that 11052016 and try to request a data manipulation such as a function call or format you will get an error as the largest data SAS currently handles, 31DEC19999 is 6588970 < 11052016.

 

The ******* usually means that you have requested SAS to display something that doesn't fit. So I suspect you don't actually have a date or you attempted to display more digits than would fit in the window.

 

If the value is currently not a date you may need to either re-import you data in a way the you can indicate that it should be a date or calculate a new variable but we would need to see actual values of the variable to suggest appropriate code.

New Contributor
Posts: 3

Re: how to transfer date to week of year

Hi thank you for your reply.

I'm sure this is a date column. 

i'm not sure whether you could see my attachment. 

i know i might be able to achieve this by change the code, but i'm wondering if there is any way throught query builder. 

Attachment
Grand Advisor
Posts: 17,355

Re: how to transfer date to week of year

Yes, it was provided above. 

 

Use a computed column and advanced expression.
 
WEEK(DateVariable, U/W/V).
 

New Contributor
Posts: 3

Re: how to transfer date to week of year

I tried this way, the computed column returns ".", as showed in my attachment.

do you know why?

 

thanks

Kira

Attachment
Attachment
Grand Advisor
Posts: 10,211

Re: how to transfer date to week of year

You may have fallen victim to a common lazy practice of calling datetime values (those that incorporate a date and time) "dates". SAS dates are counts of days, datetimes are seconds. Your example is DATETIME.

 

So you need to calculate Week(datepart(t1.Requested_date))

Grand Advisor
Posts: 17,355

Re: how to transfer date to week of year


ballardw wrote:

You may have fallen victim to a common lazy practice of calling datetime values (those that incorporate a date and time) "dates". SAS dates are counts of days, datetimes are seconds. Your example is DATETIME.

 

So you need to calculate Week(datepart(t1.Requested_date))


@ballardw Is correct, your variable is datetime not date. You can see this in your first snapshot as it has a calendar and clock symbol on the variable requested date. 

 

 

Ask a Question
Discussion stats
  • 7 replies
  • 262 views
  • 0 likes
  • 3 in conversation