BookmarkSubscribeRSS Feed
AllSoEasy
Obsidian | Level 7

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?

Thanks!!

-Ryan

1 REPLY 1
ballardw
Super User

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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 1 reply
  • 2128 views
  • 0 likes
  • 2 in conversation