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

Hi, I need to concat Date and Time using proc sql

Date  

15/05/2018

Time

8:27:30

DateTime

15/05/2018 08:27:30

 

So I did that: 🙂

 

cat(put(day(Date),z2.),'/',put(month(Date),z2.),'/',year(Date),' ',put(hour(Time),z2.),':',put(minute(Time),z2.),":",put(second(Time),z2.)) as DateTime

 

Anyone can show me another way please one that I don’t mess with the column format

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
5 REPLIES 5
Reeza
Super User

 

new_var = dhms(date, 0, 0, time);

format new_var datetime.;

This may be helpful.

https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/...

godoyau
Calcite | Level 5
Ok it works, but i need this format 15/05/18:08:27:30 and datetime. returns 15MAY18:08:27:30.
ballardw
Super User

@godoyau wrote:
Ok it works, but i need this format 15/05/18:08:27:30 and datetime. returns 15MAY18:08:27:30.

The value appears correct, what you are actually saying is that the display format does not meet you expectation/ need.

SAS provides a very large number of date, time and datetime display formats but cannot meet every single need. However you can create custom display format using Proc format with the Picture statement and directives. Warning for the code below: The quotes around the funny list of %0d/%0m/0%y:%0H:%0M:%0S must be single quotes or else SAS will think you are using macro variables. The case on the d m y H M and S are significant. Changing from 'm' to 'M' for instance will change the displayed value from month number to Minutes (and vice versa). The 0 are to display leading zeroes for values less than 10. Since this is not SAS supplied format it will be up to you to make sure the format is available when ever you need to use it. Either rerun the code every session or add the format to permanent format catalog.

 

proc format library=work;
picture mydttime
low - high= '%0d/%0m/0%y:%0H:%0M:%0S' (datatype=datetime)
;
run; 

data junk;
   x='15MAY18:08:27:30'dt;
   put x= mydttime.;
run;
novinosrin
Tourmaline | Level 20

Are you dates and time char or numeric?

godoyau
Calcite | Level 5

Numeric

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 5 replies
  • 4510 views
  • 0 likes
  • 4 in conversation