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

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

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
  • 3 replies
  • 2315 views
  • 1 like
  • 3 in conversation