BookmarkSubscribeRSS Feed
kmin87
Fluorite | Level 6

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

4 REPLIES 4
Tom
Super User Tom
Super User

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;

 

 

LeonidBatkhan
Lapis Lazuli | Level 10

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
Super User
Or try option guessingrows= :

proc import datafile="\\somedrive\test.txt"
out=master
dbms=tab
replace
;
guessingrows=max;
run;
Tom
Super User Tom
Super User

@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.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1335 views
  • 2 likes
  • 4 in conversation