BookmarkSubscribeRSS Feed
mengjiawei
Calcite | Level 5

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

 

 

7 REPLIES 7
Reeza
Super User

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

ballardw
Super User

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.

mengjiawei
Calcite | Level 5

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. 


Capture.JPG
Reeza
Super User

Yes, it was provided above. 

 

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

mengjiawei
Calcite | Level 5

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

do you know why?

 

thanks

Kira


Capture.JPGCapture1.JPG
ballardw
Super User

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))

Reeza
Super User

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

 

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 7 replies
  • 2393 views
  • 0 likes
  • 3 in conversation