03-20-2015 06:01 AM
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 !!
03-20-2015 06:05 AM
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.
03-20-2015 06:16 AM
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.
03-20-2015 12:56 PM
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.
03-20-2015 01:31 PM
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.