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

Greetings

 

I have a table that has a datetime field and would like to update the field with today's date using the datetime format.

I have seen a way of updating a number field  by doing this in the attached dataset:

 

Proc sql;

update test2

set hour = 50;

quit;

The code updates all values of the field "Hour"

 

I would like to update the field Date with today's date.

 

Furthermore, it might be required to update only a specific record say where name = 'John'. will there also be a way of updating specific record?

Thanks in advance

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

 

Proc sql;
    update test2 set date = datetime();
    alter table test2 modify date integer format=datetime16.;
quit;

Now test2 is a datetime value. NOTE: in some places you ask for a datetime value, and in other places you ask for a date value, which is it?

--
Paige Miller

View solution in original post

3 REPLIES 3
PeterClemmensen
Tourmaline | Level 20
Proc sql;
   update test2
   set hour = datetime
   where name = 'John';
quit;
PaigeMiller
Diamond | Level 26

 

Proc sql;
    update test2 set date = datetime();
    alter table test2 modify date integer format=datetime16.;
quit;

Now test2 is a datetime value. NOTE: in some places you ask for a datetime value, and in other places you ask for a date value, which is it?

--
Paige Miller
mmohotsi
Obsidian | Level 7

Greetings

 

The solution worked perfectly. The customer request that I format today's date as a datetime field to a format 2022-02-21 13:56:45. This format starts with a year as it will suits his database field

 

The datetime in the accepted solution provides a datetime format that starts with the day and not the year.

 

Is there a way to update the field with this format?

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!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 3 replies
  • 2728 views
  • 1 like
  • 3 in conversation