BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
NewUsrStat
Pyrite | Level 9

Hi guys, 

I'm trying to remove time from dates. 

The situation is the following: 

 

NewUsrStat_0-1727770428946.png

I tried to use the following code: 

data my_data_corrected;
	set my_data;
	Date_Value = input(date, anydtdte.);
        Date_Only = datepart(Date_Value);
        format Date_Only date9.; 
run;

Unfortunately it seems not to work I suppose because of the presence of blanks.

Could it be the case? 

 

After running the code dates are converted as follows: 31DEC1959.

 

Can anyone help me please? 

 

Note: the variable "date" is stored as Num, DATETIME20.

 

Thank you in advance

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

If the variable "date" is originally stored with the datetime format then it is numeric.

Use

data my_data_corrected;
	set my_data;
	Date_only= datepart(date);
        format Date_Only date9.; 
run;

The bit that date has a datetime format means it is a numeric value and use of "input" is not needed.

 

Best on this forum is to include the LOG from running the code. Copy the code with all the notes and messages from the log. Then paste that into a text box. I will place a small wager that your log shows a "numeric values were converted to character" somewhere.

View solution in original post

3 REPLIES 3
ballardw
Super User

If the variable "date" is originally stored with the datetime format then it is numeric.

Use

data my_data_corrected;
	set my_data;
	Date_only= datepart(date);
        format Date_Only date9.; 
run;

The bit that date has a datetime format means it is a numeric value and use of "input" is not needed.

 

Best on this forum is to include the LOG from running the code. Copy the code with all the notes and messages from the log. Then paste that into a text box. I will place a small wager that your log shows a "numeric values were converted to character" somewhere.

NewUsrStat
Pyrite | Level 9

You won... 🙂

Kurt_Bremser
Super User

There's a reason why Maxim 2 is so far up on the list. Always post the log when a step does not work as expected. The log is our #1 diagnostic tool.

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!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 711 views
  • 3 likes
  • 3 in conversation