BookmarkSubscribeRSS Feed
fadel
Calcite | Level 5

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 !!

5 REPLIES 5
LinusH
Tourmaline | Level 20

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
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

ballardw
Super User

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.

Reeza
Super User

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.

fadel
Calcite | Level 5

It works very good. thanks  Smiley Happy

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 5 replies
  • 832 views
  • 1 like
  • 5 in conversation