DATA Step, Macro, Functions and more

Best proc to import data into sas

Reply
Contributor
Posts: 32

Best proc to import data into sas

Hi,

i have a text file in wich dataare separated by tabulation, i used proc import but it format some variables to numeric, also i dont know how to calculate length of colomnes !!

Super User
Posts: 5,424

Re: Best proc to import data into sas

What is best depends on your requirements and the situation.

If you want control, a data step is "best".

Either way, you need a file specification so that your imported data will be consistent according to your input file.

Data never sleeps
Super User
Super User
Posts: 7,942

Re: Best proc to import data into sas

Agree with Linus Hjorth.  First step - data transfer agreement document which details the structure of the file, column widths, formats, dvgs etc. necessary to the use of the data.  Unfortunately as you are using a delimited (or fixed width) text file it is not self describing like XML, so you need additional information.

Super User
Posts: 11,343

Re: Best proc to import data into sas

With first time data sources that are delimited files I generally run Proc Import and capture the code generated when the procedure runs. Then I have a place to put in additional pieces to hand cases like codes that default to numeric because they look like numbers but shouldn't be treated as such due to significant leading zeros or things like phone numbers or product codes. You can modify the code to change the read/stored lengths of variables, add labels (REALLY recommend this) and apply any information that may be available on the layout as RW9 mentions.

Since the code is a data step you can also add in many data validation bits such as dates indicating the future that shouldn't be, out of expected ranges, unknown codes. For instance: I have a data source where some of the users routinely enter 0 for missing data when 0 is not an acceptable value. I can either have the program write a note to the log or an output dataset or file with information to identify the record for correction or have code that just sets those to missing.

Super User
Posts: 19,769

Re: Best proc to import data into sas

Start off by using proc import.

The log will generate the data step code with what it thinks are the best format/informats for the variables.

Copy the code from the log and use it to replace your proc import - use CTRL+ALT+click to remove line numbers when selecting

Modify the code as required according to the metadata specifications, or what you think the variables should be if you don't have the metadata.

Contributor
Posts: 32

Re: Best proc to import data into sas

It works very good. thanks  Smiley Happy

Ask a Question
Discussion stats
  • 5 replies
  • 211 views
  • 1 like
  • 5 in conversation