DATA Step, Macro, Functions and more

How do I read messy CSV data in SAS without using PROC Import?

Reply
New Contributor
Posts: 3

How do I read messy CSV data in SAS without using PROC Import?

[ Edited ]

I have CSV data. Can anyone help reading it in SAS without using proc import?

Attachment
PROC Star
Posts: 7,366

Re: help reading messy data from csv

If you run proc import SAS will write and run the data step that you would otherwise have to write to read in the file.

 

Proc import saves you the time of getting the variable names from the first records, determining which variables are numbers and which are characters, and identifying each variable's length.

 

Art, CEO, AnalystFinder.com

 

New Contributor
Posts: 3

Re: help reading messy data from csv

please without using proc import

PROC Star
Posts: 7,366

Re: help reading messy data from csv

If you run proc import it will not only do the job, but show you the code that answers your question. 

 

On the other hand, if you want a lesson, take a look at: https://support.sas.com/techsup/technote/ts673.pdf

 

Art, CEO, AnalystFinder.com

 

SAS Employee
Posts: 286

Re: help reading messy data from csv

Why can't you use PROC IMPORT?

 

Vince DelGobbo

SAS R&D

Super User
Posts: 17,963

Re: help reading messy data from csv

[ Edited ]

kekou wrote:

i have a CSV data.  can anyone help reading it in SAS without using proc import?


Is this a file that should be public and available to anyone or does it contain confidential information? If this is a work file you may have violated confidentiality rules. 

Super User
Super User
Posts: 6,502

Re: How do I read messy CSV data in SAS without using PROC Import?

CSV files are easy to read. Something like your file with only three variables is easier to read WITHOUT using PROC IMPORT.

data want ;
  infile 'zipcode.csv' dsd truncover firstobs=2;
  input var1-var3 ;
run;

Now if you want you can use more meaningful names for your variables.

If it really was a messy file then you could try reading the fields as characters strings and adding extra code to convert the strings into the types of values you need.

Ask a Question
Discussion stats
  • 6 replies
  • 230 views
  • 0 likes
  • 5 in conversation