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
new_var = dhms(date, 0, 0, time);
format new_var datetime.;
This may be helpful.
new_var = dhms(date, 0, 0, time);
format new_var datetime.;
This may be helpful.
@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;
Are you dates and time char or numeric?
Numeric
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.
Ready to level-up your skills? Choose your own adventure.