Hi,
I am trying to transform character imported timestamp variable to numeric timestamp variable so that I can change and play around with the variable. When I try to use input function, I keep getting errors.
The original timestap looks like the one below and I want to convert it to a format .
I run this code
data Z11; set Z10;
datadate = input(TIMESTAMP_UTC,8.);
format datadate YYMMDDN8.;
run;
then I keep getting errors:NOTE: Invalid argument to function INPUT at line 1015 column 12
All help is appreciated
No, you don't have to do the DATALINES statement. That was done for me to reproduce your issue and test whether my solution works. Just run the second chunk of code I provided:
data want;
set have;
datadate_nofmt = input(timestamp_utc, yymmdd10.);
datadate = put(input(timestamp_utc, yymmdd10.), yymmddn8.);
run;
You don't even have to do the 'datadate_nofmt' part. That was done just to show you what's going on.
Try this. I specified an INFORMAT to read in the date as numeric, and then I converted it to your desired FORMAT (yymmddn8).
data have;
input timestamp_utc $23.;
datalines;
2010-01-01 03:30:53.85
;
run;
data want;
set have;
datadate_nofmt = input(timestamp_utc, yymmdd10.);
datadate = put(input(timestamp_utc, yymmdd10.), yymmddn8.);
run;
timestamp_utc datadate_nofmt datadate 2010-01-01 03:30:53.85 18263 20100101
thank you for reply.
So will I have to inclued all timestamps in datalines? I have 53000 timestamps. Will I include all of them in the datalines?
No, you don't have to do the DATALINES statement. That was done for me to reproduce your issue and test whether my solution works. Just run the second chunk of code I provided:
data want;
set have;
datadate_nofmt = input(timestamp_utc, yymmdd10.);
datadate = put(input(timestamp_utc, yymmdd10.), yymmddn8.);
run;
You don't even have to do the 'datadate_nofmt' part. That was done just to show you what's going on.
thank you! cheers!
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.
Ready to level-up your skills? Choose your own adventure.