I am importing a txt file to sas. the ID field has leading zeros which i wish to retain. after importing i find that the zeros are not being imported. how can I imported the data while retaining the zeros.
Partly the answer depends on what you want to do with ID and whether ID is character or numeric. If ID is numeric, then SAS will not -store- leading zeroes -- however, you can -display- leading zeroes by simply using a FORMAT statement (probably best in this case to permanently associate a format with the ID variable).
[pre]format ID z5.;
If you put that format statement in the program where you read the text file (assuming you're using a DATA step program), then SAS would format the ID to be 5 digits, with leading zeroes. So the internally stored number '123' would display on all reports as '00123', for example. If you are importing the data without a DATA step, then you can always modify the format attribute with PROC DATASETS, after the dataset is created.
However, if you read ID as a character variable and then store it as a character variable, SAS will both -store- and -display- the leading zeroes without needing a user defined format.
input name $ as_num_id as_char_id $;
format as_num_id z5.;
alan 00123 00123
bob 00234 00234
cathy 00345 00345
dana 00456 00456