BookmarkSubscribeRSS Feed
ramya_sahu
Obsidian | Level 7

Hi,

 

 I have csv files having datetime variable in both text & datetime formats.

 

So, is there any way to import the file with datetime format?

 

if i import the data successfully, then i am having problem while appending with similar set of data.

 

your suggestion here will be highly appreciated.

2 REPLIES 2
Reeza
Super User

@ramya_sahu wrote:

 

 

So, is there any way to import the file with datetime format?

 

 


 

Get the import correct. 

Use the correct informats to specify the input format in a data step. If you use PROC IMPORT then you should make sure to set GUESSINGROWS to a very large number, possibly the size of the entire file so the data can be read in correctly. 

 


@ramya_sahu wrote:

 

if i import the data successfully, then i am having problem while appending with similar set of data.

 

.


If you make sure that you specify the formats for the files and import all in the same manner then the issue will go away. 

ballardw
Super User

@ramya_sahu wrote:

Hi,

 

 I have csv files having datetime variable in both text & datetime formats.

 

if i import the data successfully, then i am having problem while appending with similar set of data.

 


It sounds like you are using proc import multiple times. Proc import has to guess characteristics of variables based on the values it sees. So multiple Proc Import on different files can result in different data types, lengths, informats and formats.

 

If these files are supposed to be the same structure use Proc import only one time. Use a large value for the guessingrows option, as large as the number of rows in the data set if it is less than 32,000 records.

Proc import will generate data step code that should appear in the log. Copy that data step from the log and paste into the editor.

Examine the informat statements. If you see a character informat for a variable you think should be numeric, date, datetime or time then you can change that. At the same time look at the character variables to see if the lengths are appropriate. A variable that is blank in the first few rows of a data set may get a length of 1 when it should be 25. I generally increase the length of character fields by 10 to 20% unless there is a file format document that says what the length should be, in which case use that length.

 

SAVE the modified program. Re-run with the new code.

To read the next data set use the same data step just change the name of the input file and the output data set name. Then all of the files will have the same characteristics.

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 Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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