csvimportsasproc

How to import codes beginning with "0" from CSV to SAS as strings?


I've been trying to import in SAS a variable of codes starting with a "0" from a csv file, but the "0" at the beginning disappears (for instance "01111" becomes "1111" in SAS).

The problem is that SAS always imports this variable as a numeric variable when using proc import. I know the problem could be solved using "infile". The thing is I would like to avoid using "infile" and the data step, because I have many variables and all the others are imported correctly.

Do you have any idea how to do this ?

I've tried the DBDSOPTS function but it doesn't seem to work:

proc import out=out.data
datafile="&path./datafile.csv" 
dbms=csv
replace;
getnames=yes;
delimiter=";";
DBDSOPTS= "DBTYPE=(var1='CHAR(3)')";
run;

NB: I cannot concatenate the code with a "0" (ex: cat("0",var1)) because some codes start with other numbers (ex: 12000).


Solution

  • If you are concerned about how PROC IMPORT guessed to read your file then write the code to read it yourself. You could use the code PROC IMPORT generated as a guide.