A couple of small issues:
1. I have a datetime26.7 variable (flightdatetime) that has values like: 26SEP2018:00:51:48.0000000
I need to create a new one that truncates the seconds....so I would have: 26SEP2018:00:51 as a datetime variable (no seconds)
2. I also have another datetime22.3 variable (flightdategmt) that looks like 26SEP2018:00:00:00.000. There is also a variable called gmttime, which is character. An example is 0051. I need to be able to add the 0051 to flightdatetimegmt so it will read, as a datetime, 26SEP2018:00:51 (no seconds).
Thanks!
See the documentation for the datetime format https://documentation.sas.com/?cdcId=pgmmvacdc&cdcVersion=9.4&docsetId=leforinforref&docsetTarget=n0...
I had tried datetime15. for number 1....but the underlying data is still stored with the seconds? Is the datetime15. ok as I need to compare times later without seconds
thx
Formats do not change the underlying data. They change the appearance when a human looks at it.
If you really want the date and time in minutes, with seconds forced to be zero, you'd have to change the underlying data, or do the comparisons so seconds are ignored. All of this is simple math.
To take any datetime with seconds, and "round down" to the exact minute where seconds are forced to be zero:
newdatetime = 60*floor(datetime/60);
You can do like this
1)
data test1;
dt='26SEP2018:00:51:48.0000000'dt;
dtnew=dt;
format dt datetime26.7 dtnew datetime15.;
run;
2)
data test2;
flightdategmt='26SEP2018:00:00:00.000'dt;
gmttime='0051';
new_flightdategmt=sum(flightdategmt, input(cats(substr(gmttime, 1, 2), '.', substr(gmttime, 3, 2)), time5.));
format flightdategmt datetime22.3 new_flightdategmt datetime15.;
run;
@BCNAV wrote:
A couple of small issues:
1. I have a datetime26.7 variable (flightdatetime) that has values like: 26SEP2018:00:51:48.0000000
I need to create a new one that truncates the seconds....so I would have: 26SEP2018:00:51 as a datetime variable (no seconds)
Example using INTX to round to minutes:
data example; x='26SEP2018:00:51:48.0000000'dt; y=intnx('minute',x,0,'B'); format x y datetime26.7; run;
to do similar with a character value adding 51 minutes:
data example; x='26SEP2018:00:00:0.0000000'; y=put (intnx('minute',input(x,datetime27.7),51,'B'), datetime27.7); run;
use the appropriate format/informat for your need.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.