Below is sample code I am using. Information was replaced with an arbitrary information just for privacy reasons.
when I import the text file that has rows of numbers that have leading zeros in sas, I get the information with the leading zeros dropped in the master datatable in sas. how do I make sure I maintain the leading zeros when I import the data
proc import datafile="\\somedrive\test.txt"
out=master
dbms=dlm
replace
;
run;
the test.txt file has these social security numbers listed in rows
000111111
222222222
044444444
Don't use PROC IMPORT.
You could try modifying the code that PROC IMPORT generates (but it generates really ugly SAS code). It is usually better (and often faster) to just write your own code.
data master;
infile "\\somedrive\test.txt" dsd truncover firstobs=1;
input ssn $9. ;
run;
Hi kmin87,
Yes, you can either make them type of character (e.g. using $9. informat as @Tom suggested), or if you keep it numeric, you can also define FORMAT SSN z9 (which will show leading zero even when the number is stored without them).
Another way to deal with SSNs is to store them as NUMERIC values and apply FORMAT SSN11. (in the latter case, formatted values will show as NNN-NN-NNNN, that is with hyphens).
Hope this helps.
@Ksharp wrote:
Or try option guessingrows= :
proc import datafile="\\somedrive\test.txt"
out=master
dbms=tab
replace
;
guessingrows=max;
run;
That will not make any difference for this problem. PROC IMPORT will decide the variable is numeric if the only values it sees in the column are digit strings. It is NOT smart enough to attach the Z format to the numeric variable.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.
Ready to level-up your skills? Choose your own adventure.