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

I am incredibly new to sas or any database programming. I use SAS EG as I find it easier to work with. Question, how can I change my datetime column into a Date9. format so I can match using these dates? I would like to do this using the query builder if possible. When I use the datepart function in the advanced expressions I end up with negative numbers on my new calculated column.

 

Thanks 🙂

 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

Okay: 

1. Query builder

2. Add table

3. Choose columns

4. Add new computed column

5. Advanced expression

6. Enter an expression: datepart(your_datetime)

7. Modify additional options-- change the format to datew.d and choose 9

8. Finish

 Now, run

 

View solution in original post

6 REPLIES 6
novinosrin
Tourmaline | Level 20

are there any dates before 01jan1960?  Did you format the date? 

FLCrime
Fluorite | Level 6

Image below is all I know at this point. This is prior to me attempting the calculated column.

 

Capture.PNG

novinosrin
Tourmaline | Level 20

Okay: 

1. Query builder

2. Add table

3. Choose columns

4. Add new computed column

5. Advanced expression

6. Enter an expression: datepart(your_datetime)

7. Modify additional options-- change the format to datew.d and choose 9

8. Finish

 Now, run

 

FLCrime
Fluorite | Level 6

Thank you so much. It always turn out to be something super simple that I missed or had no knowledge of.

novinosrin
Tourmaline | Level 20

No worries. It's one of those days. I must confess I still do not know what a computer,an operating system is. lol 

Reeza
Super User

You can have negative dates so SAS is likely correct. 

 

SAS stores dates/datetimes as a number from a reference date, in this case January 1, 1960. So any dates before Jan 1, 1960 are negative. Apply a date format to the field and SAS will show the data correctly. 

 

Here's a great, but longer and in depth, reference for dates and times in SAS. I highly recommend reading this if you're working with dates and datetimes extensively.
https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/...

 


@FLCrime wrote:

I am incredibly new to sas or any database programming. I use SAS EG as I find it easier to work with. Question, how can I change my datetime column into a Date9. format so I can match using these dates? I would like to do this using the query builder if possible. When I use the datepart function in the advanced expressions I end up with negative numbers on my new calculated column.

 

Thanks 🙂

 


 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 6 replies
  • 4033 views
  • 3 likes
  • 3 in conversation