Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

comma delimited file import - CHAR and NUM/SAS picks wrong data type!

Status
Not open for further replies.

mstrgrl

Technical User
Oct 14, 2003
44
US
I'm having a time of this. I haven't done SAS for years, and I'm trying to import a raw datafile which is exported from my database and is comma delimited. It contains num and char data, and it is important that certain columns import as the right data type or my program will blowup. I have tried the import wizard, proc import, writing out the data/infile/input statement with no luck. I realize that SAS scans the first 8 lines of data and picks the "prevalent" data type -- How can I get around this?? I tried to update the SAS selected data type through the EFI thingie but it only lets me update 1 column then stops.

Thanks in advance!
 
use something like this:-
Code:
data mydat;
  infile '<the datafile>' recfm=v lrecl=2056 dsd dlm=',' missover firstobs=2;

  length var1  $20
         var2   8
         ....
         ;
  input var1
        var2
        ...
        ;
run;
Notes
the DLM option isn't really required, DSD defaults to a comma delimited file.
DSD tells SAS that two consequetive delimiters means a missing value, otherwise it'll skip it and read the next value in.
missover covers scenarios where the last column is missing.
firstobs=2 drops the first record (useful when you have a header row.

Use the length statement to fix the columns to a specific type before your input statement. This particular method almost never fails me. Remember to use informat statements for any date fields or formatted data.

If you still have problems, post some sample data and your log.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top