DATA Step, Macro, Functions and more

Cannot properly informat date from csv to sas

Accepted Solution Solved
Reply
Contributor
Posts: 21
Accepted Solution

Cannot properly informat date from csv to sas

Hi,

 

I am unable to properly informat the date from my csv file. When I do a proc import or using the import wizard, the date is cut off to have a format of $1. and informat of $1.

 

proc import datafile='C:***********.csv'
 dbms=csv out=work.test replace;
run;

 

I have tried including "input Date MMDDYY10." in the proc import statement but it does not work.

My date format from the csv file is 12/31/2017 but it is currently only showing up as the first character or "1". 

 

Thank you for your help!

 


Accepted Solutions
Solution
‎02-24-2018 04:24 PM
Super User
Posts: 23,332

Re: Cannot properly informat date from csv to sas

GUESSINGROWS=MAX;

In general, PROC IMPORT guesses, and it can guess wrong. Especially if the first records it encounters are only length 1 or it has mixed values. 

 

You can set GUESSINGROWS=MAX to avoid this but it scans the whole file first which can be time consuming. In general, you're better off writing a data step with INPUT and specifying the lengths ahead of time. See the log for an example of how you would write the code or to use it as starter code and modify as needed.

 


dlazer1 wrote:

Hi,

 

I am unable to properly informat the date from my csv file. When I do a proc import or using the import wizard, the date is cut off to have a format of $1. and informat of $1.

 

proc import datafile='C:***********.csv'
 dbms=csv out=work.test replace;
run;

 

I have tried including "input Date MMDDYY10." in the proc import statement but it does not work.

My date format from the csv file is 12/31/2017 but it is currently only showing up as the first character or "1". 

 

Thank you for your help!

 


 

View solution in original post


All Replies
PROC Star
Posts: 2,319

Re: Cannot properly informat date from csv to sas

The import wizard generates code.

What does that look like? Would modifying it be a solution?

Otherwise it's hard to comment without seeing the first few lines of the CSV file.

Solution
‎02-24-2018 04:24 PM
Super User
Posts: 23,332

Re: Cannot properly informat date from csv to sas

GUESSINGROWS=MAX;

In general, PROC IMPORT guesses, and it can guess wrong. Especially if the first records it encounters are only length 1 or it has mixed values. 

 

You can set GUESSINGROWS=MAX to avoid this but it scans the whole file first which can be time consuming. In general, you're better off writing a data step with INPUT and specifying the lengths ahead of time. See the log for an example of how you would write the code or to use it as starter code and modify as needed.

 


dlazer1 wrote:

Hi,

 

I am unable to properly informat the date from my csv file. When I do a proc import or using the import wizard, the date is cut off to have a format of $1. and informat of $1.

 

proc import datafile='C:***********.csv'
 dbms=csv out=work.test replace;
run;

 

I have tried including "input Date MMDDYY10." in the proc import statement but it does not work.

My date format from the csv file is 12/31/2017 but it is currently only showing up as the first character or "1". 

 

Thank you for your help!

 


 

Contributor
Posts: 21

Re: Cannot properly informat date from csv to sas

Thank you! This worked. 

☑ This topic is solved.

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

Discussion stats
  • 3 replies
  • 95 views
  • 1 like
  • 3 in conversation