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

Hello SAS world,

 

I'm working with DI Studio (v4.901) to import flat files, perform some minor editing and sorting, and append the results into a permanant file where Dataflux will take the records and standardize the data.

 

My date column in question is sent as CCYYMMDD.  (20170119)

I'm importing it as length 8, informat yymmdd8.0, format date9.

 

So.. my results are 19JAN2017.

 

My final transformation is a table loader (appending records) into a end result table.

By the end of my process, I need to change this date value into a datetime22 format to match the end result table. 

I expect the 'time' value to be 0, but the date to be in the date9. format still. (19JAN2017:00:00:00)

 

Can I do this by changing the mapping at time of the table import.. or in one of my transformations such as the table loader?

 

Any helpful suggestions are apppreciated,

Chris N.

 

 

- Chris N.
1 ACCEPTED SOLUTION

Accepted Solutions
RLigtenberg
SAS Employee

See if this helps. Uses mock data to resemble your scenario.

 

Regards,

Robert

View solution in original post

12 REPLIES 12
cnilsen
Quartz | Level 8
Would this be easiest at the time I am initially reading the flat file?
- Chris N.
Patrick
Opal | Level 21

You could use informat anydtdtm. and convert the source date string to a SAS datetime value when reading the flat file.

 

%let save_datestyle=%sysfunc(getoption(datestyle));
options datestyle=ymd;
data test;
  format my_dttm datetime22.;
  my_dttm=input('20170119',anydtdtm.);
run;
options datestyle=&save_datestyle;

 

The anydt... informats ingest different date string patterns. This bears the risk that for your data an invalid date string gets converted to a SAS Datetime value without warning; i.e. a date string of 20171901 which would be invalid for you but which would get read by the anydt... informat assuming it's a date string in a YDM pattern.

Your choice!

Kurt_Bremser
Super User

@cnilsen wrote:
Would this be easiest at the time I am initially reading the flat file?

Why not? The important thing is to be consistent about datatypes, so you don't get unexpected results by comparing dates to datetimes.

So yes, implement the conversion when reading the flat file.

cnilsen
Quartz | Level 8

I still cannot get my head around this. Everything I have tried so in a transformation far WILL create a date/timestamp. But it always defaults my date to 1JAN1960. and time value 00:00:01. I'm at a point where I'm going to go back to the As400 system and add a blank time value to the outbound table I'm going to process later with DI.

 

I also tried this variations of this, which resulted in a null value for the column:

 

 

 

 

 

 

- Chris N.
ballardw
Super User

And assign the desired format: format date datetime22. ;

RLigtenberg
SAS Employee

See if this helps. Uses mock data to resemble your scenario.

 

Regards,

Robert

cnilsen
Quartz | Level 8
I like this.. I'll work on it and get back to you.!

-Chris.
- Chris N.
RLigtenberg
SAS Employee

Page 2, just in case...only page 1 shows in my browser.

cnilsen
Quartz | Level 8

Robert..

 

Success at last !.

I was close to this in my expression building, but I had the formats all wrong, so my results were never correct.

 

I appreciate taking the time to create a document to show me how you did this. It was extremely helpful, and now gets added to many other help docs I have accumulated for future reference.

 

Regards and Thanks,

Chris.

 

 

- Chris N.
LinusH
Tourmaline | Level 20
You haven't shown what you have actually tried.
It sounds like you have successfully imported the cyymmdd to a SAS numeric column with a date. format and it's showing the correct date?
Then, in the table loader use the dhms function as suggested by @Kurt_Bremser, as a mapping expression.
If you tried that, show the generated step code.
Data never sleeps
cnilsen
Quartz | Level 8
I'm putting together a document to upload what I have so far...
- Chris N.

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!

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 12 replies
  • 3037 views
  • 2 likes
  • 6 in conversation