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 !!
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.
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.
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.
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.
It works very good. thanks
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.
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.