I am having a problem importing a list of customer ids correctly using proc import. The customer id is made up a 20 digit number which should be treated as a string. when I use proc import the id gets converted into a number and written in shortened format (e.g. 2.001365E18 ). When I try to run a format "best32." on the field, I get the length of the id back, but most of the ending digits are wrong. Can someone help me? There must be a way to make proc import treat this field correctly.
Here is my original data file:
here is my import/format statement:
PROC import out = pne_db
datafile = "C:\Temp\test_forum.txt"
DBMS = DLM REPLACE;
format cust_id best32.;
Here is my result:
CUST_ID ST_CD age
2001365500203000064 SC 55.14
2001365600005000192 FL 68.44
2001365600006003456 FL 63.22
2001365600006003456 FL 68.33
If you are destined to use PROC IMPORT rather than coding your own DATA step, one technique that may work, given your example input file, would be to append a unique prefix character to the CUST_ID field and then strip off the character after the data is read up. So, if you do not have control of the layout of your raw, input data creating, then you would need to code a DATA step such as:
PUT @1 'Z' _INFILE_;
Then, after the PROC IMPORT, you would need to code some DATA step logic to strip off the leading "Z" character with something like:
CUST_ID = SUBSTR(CUST_ID,2);
I typically use this technique when generating Excel data with SAS, as CSV-formatted, delimited files, adding a single-quote character prefix, so Excel will treat the data as text during wizard-import without my telling it to do so.