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: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 4097 views
  • 3 likes
  • 3 in conversation