Hi Statalisters,

I try to add leading zeros for my string variable named cusip by using the code -gen cusipnew = string(real(cusip),"%09.0f")-.
But the result seems not ideal because this string variable contains both numbers and letters. The result for those observations containing letters shows in missing observations. Another tricky problem is that the digit for the string variable is not congruent, which means some will add leading zeros, some will not. Is there any better solution to this questions?

Thanks in advanced.

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input str17 cusip str9 cusipnew
"361105"    "000361105"
"361105"    "000361105"
"361105"    "000361105"
"361105"    "000361105"
"361105"    "000361105"
"361105"    "000361105"
"361105"    "000361105"
"361105"    "000361105"
"361105"    "000361105"
"886309"    "000886309"
"02376R102" "."        
"02376R102" "."        
"02376R102" "."        
"02376R102" "."        
"02376R102" "."        
"02376R102" "."        
"02376R102" "."        
"02376R102" "."        
"02376R102" "."        
"125141101" "125141101"
"125141101" "125141101"
"125141101" "125141101"
"125141101" "125141101"
"125141101" "125141101"
"125141101" "125141101"
end