Help using Base SAS procedures

Force text formatting on proc import

Frequent Contributor
Posts: 109

Force text formatting on proc import

Hi All,

I am using Proc Import to import a .csv file into SAS. I need to force some columns to be treated as text during the import, I have two issues: there is an "account number" column which is *numeric* however many accounts having lead 0's that must remain (i.e. i can NOT have "00000245" imported as "245" as it is currently doing), also there is a "date" column which is a date in mm/dd/yyyy format, however it is missing for many of the rows -- this is expected in terms of my data to have some rows missing a date, but the rows should still be imported all the same, but because it autoformats that column to a date i get errors for "invalid data" on each row with a missing date, and soon the import fails because of too many invalid data errors.

Is there anyway I can force columns to import as pure text and ignore formatting with proc import? If not, is there another way that I can import this data into SAS in this fashion?



Super User
Posts: 13,508

Re: Force text formatting on proc import

Posted in reply to AllSoEasy

Use the import then recall the generated datastep code, use F4 or go to the log and copy back into the editor. The variable informat and informat assignments will show in the code. Change them from probably best3.2 or similar to $20. or what ever length you need. Then add a $ after the variable in the INPUT statement  corresponding those variables.

You can suppress the warning messages for the dates by using ?? after the variable name in the input statement.

If you are going to read the same data format multiple times generating datastep code this way is very beneficial as you can make adjustments to character variables that may change size such as city names or customer comments and allow additional room for later versions.

Also adding meaningful labels will likely be helpful in the long run.

Ask a Question
Discussion stats
  • 1 reply
  • 2 in conversation