DATA Step, Macro, Functions and more

trouble reading datatime value from tab separated text file

Accepted Solution Solved
Reply
Regular Contributor
Posts: 203
Accepted Solution

trouble reading datatime value from tab separated text file

I am using this code, which was originally generated in terms of the data formats using an import task:

 

DATA Bla;
    LENGTH
        Timestamp          8 ;
    FORMAT
        Timestamp        DATETIME18. ;
    INFORMAT
        Timestamp        DATETIME18. ;
    INFILE "&BaseFolder.&FileName2."
	        ENCODING="LATIN9"
	        TERMSTR=CRLF
	        DLM='09'x
	        MISSOVER
	        DSD 
			firstobs=2;
    INPUT
        Timestamp        : ?? ANYDTDTM19. ;
RUN;

Unfortunately, I now get errors  and funny entries like this:

 

 ******************

 

for source data like this:

 

31/05/2016 00:00:00

 

Can someone please advice how to potentially adjust the above formats? Thanks!


Accepted Solutions
Solution
‎02-21-2018 11:12 AM
Valued Guide
Posts: 521

Re: trouble reading datatime value from tab separated text file

Posted in reply to csetzkorn

No problem, when using anydtdtm. instead of anydtdtm19.:

data work.forum;
   a = '31/05/2016 00:00:00';
   b = input(a, anydtdtm.);

   format b DATETIME18.;
run;

 

 

View solution in original post


All Replies
Super User
Posts: 9,914

Re: trouble reading datatime value from tab separated text file

Posted in reply to csetzkorn

I'd read it into a character variable, convert the date and time parts separately (substr() and input() functions), and put together with result = date * 86400 + time.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Solution
‎02-21-2018 11:12 AM
Valued Guide
Posts: 521

Re: trouble reading datatime value from tab separated text file

Posted in reply to csetzkorn

No problem, when using anydtdtm. instead of anydtdtm19.:

data work.forum;
   a = '31/05/2016 00:00:00';
   b = input(a, anydtdtm.);

   format b DATETIME18.;
run;

 

 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 100 views
  • 1 like
  • 3 in conversation