Hi all. I have a dataset with many 993,664 Brazilian zip codes (called CEP) that I need to use.
CEPs are eight digits-long. Several CEPs have one leading zero. However, the dataset contains some CEPs without the leading zero.
Thus, I need to include the leading zero to these CEPs. I’m having trouble doing it.
What I tried to do:
// it didn’t work - error r(120)
// I tried to follow what Nick Cox did in another post on this issue. The string values were rounded up.
Important: only CEPs with less than eight digits must receive a leading zero. CEPs that already have eight digits must remain as they are.
Can someone help?
Thank you.
CEPs are eight digits-long. Several CEPs have one leading zero. However, the dataset contains some CEPs without the leading zero.
Thus, I need to include the leading zero to these CEPs. I’m having trouble doing it.
What I tried to do:
Code:
format cep_string %08.0f
Code:
gen cep_1 = substr(8 * "0", 1, 8 - length(cep_string)) + cep_string gen cep_2 = string(real(cep_string), "%08.0f")
Important: only CEPs with less than eight digits must receive a leading zero. CEPs that already have eight digits must remain as they are.
Can someone help?
Thank you.
Code:
* Example generated by -dataex-. For more info, type help dataex clear input str74 ds_endereco_locvt_original long cep str8 cep_string "AVENIDA EULÁLIO MODESTO, N 2408" 68960000 "6.90e+07" "RUA CARLOS DE LIMA 1729 - 413-2538" 76929000 "7.69e+07" "CONJUNTO HABITACIONAL FRANCISCO WILKER CAMPELO S/N" 62970000 "6.30e+07" "AV. OZANAN LEVINDO COELHO, 590" 37280000 "3.73e+07" "RUA SÃO PAULO NÚMERO 3435" 76974000 "7.70e+07" "RUA POTIGUARA, 340" 16100000 "1.61e+07" "RUA ABATI, 10" 30525260 "3.05e+07" "AVENIDA SYCABA, 1200" 32611292 "3.26e+07" "AV. FREI BENJAMIM, S/N - ZONA URBANA" 45025101 "4.50e+07" "RUA WILSON LAGO, 392" 25540020 "2.55e+07" "RUA DES PONTES VIEIRA, 575" 62680000 "6.27e+07" "RUA CARLOS PINTO FILHO, S/N" 12630000 "1.26e+07" "RUA SAN GENARO, 320" 8584584 "8584584" "VILA SAQUINHO" 63270000 "6.33e+07" "AVENIDA TAPAJÓS S/N" 68379500 "6.84e+07" "SEPN 707/907" 70790075 "7.08e+07" "CONSULADO GERAL DO BRASIL EM MIAMI" 11111111 "1.11e+07" "AV MANOEL NOVAES, S/N - ZONA RURAL" 44920000 "4.49e+07" "VILA DO POÇO GRANDE" 63580000 "6.36e+07" "RUA XEXEU, 72 - ZONA URBANA" 86702320 "8.67e+07" "RUA PADRE JOÃO REITZ, N 435" 88960000 "8.90e+07" "QUINTA AVENIDA, 550 - ZONA URBANA" 41746900 "4.17e+07" "RUA PARIQUIS SN" 66030690 "6.60e+07" "AV. PRESIDENTE KENNEDY, 635" 24445000 "2.44e+07" "RUA MONTE ALEGRE, 984" 5014001 "5014001" "RUA SANTA HELENA, S/N, PARQUE SÃO PEDRO, TARUMA" 69021015 "6.90e+07" "ESTRADA MUNICIPAL" 18310000 "1.83e+07" "BAIRRO DOS PAES, S/N" 18310000 "1.83e+07" "RUA CUIABÁ, 401" 99345000 "9.93e+07" "RUA HUMBERTO DE CAMPOS, S/N - ZONA URBANA" 45638000 "4.56e+07" "RUA APARICIO MARIENSE, 1777" 97670000 "9.77e+07" "AV. NILTON PENA BOTELHO 458" 27175000 "2.72e+07" "RUA QUATORZE DE JULHO, S/N" 26086425 "2.61e+07" "SÍTIO JUCA PE-130, KM 08" 55790000 "5.58e+07" "AV MASCARENHAS DE MORAIS S/N" 57480000 "5.75e+07" "RUA MADRE MONICA MARIA, N. 661 CEP 87.040-440" 87040440 "8.70e+07" "RUA CARLOS CHAGAS, 296" 39880000 "3.99e+07" "RUA LAGOA SECA, 67" 3462100 "3462100" "POVOADO BOA SORTE - ZONA RURAL" 48580000 "4.86e+07" "RUA PROFESSOR PEDRO VIRIATO PARIGOT DE SOUZA, 5300" 81280330 "8.13e+07" "PIQ( PROGRAMA DE INTEGRAÇÃO DE QUADRAS) Q. 06 LT. 02, SETOR VEREDAS" 72726125 "7.27e+07" "RUA BEZERRA DA PALMA ,SN " 50770690 "5.08e+07" "RUA RAFAEL ANUNCIATO, 255" 8500000 "8500000" "RUA HUM, 188" 35480000 "3.55e+07" "AV. DO CONTORNO, S/N" 65080805 "6.51e+07" "RUA JOÃO FRANCISCO LEAL, 142" 13223091 "1.32e+07" "AVENIDA MAZAGÃO, N. 105" 68920000 "6.89e+07" "AV DUQUE DE CAXIAS" 79240000 "7.92e+07" "RUA ANTONIO SAVI, 379" 88940000 "8.89e+07" "AV MAGALHÃES BARATA , S/N" 68610000 "6.86e+07" "RUA DOS IMIGRANTES, N. 184" 88955000 "8.90e+07" "RUA SAO JOSE S/N" 68524000 "6.85e+07" "RUA ACÁCIA DOS SANTOS PEREIRA, S/N" 11534730 "1.15e+07" "PRAÇA DOM JOSÉ THOMAZ, S/N" 49075400 "4.91e+07" "RUA JOSÉ SARTURI, 01" 99490000 "9.95e+07" "PRAÇA ADALBERTO RIBEIRO, S/N" 65130000 "6.51e+07" "R MANDAGUAÇU, 100" 87070220 "8.71e+07" "AV. CARLOS LIVIERO, 600" 4186100 "4186100" "R. TIRADENTES, 847" 79904646 "7.99e+07" "RUA ANTONIO PEREIRA,1495" 60760525 "6.08e+07" "RUA PORTO DO BEZERRA, 25" 8440000 "8440000" "ESTRADA GERAL, S/N" 88590000 "8.86e+07" "LOCALIDADE LAGOA SECA" 64235000 "6.42e+07" "RUA PADRE AGOBAR VALENÇA, S/N (AO LADO DO CAIC)" 55297400 "5.53e+07" "RUA MAL. DEODORO DA FONSECA, 908" 86410000 "8.64e+07" "RUA BOTUPORÃ, QUADRA 2, CHÁCARA PERSEVERANÇA, S/N - ZONA URBANA" 41100060 "4.11e+07" "R. PRINCIPAL, S/N" 29330000 "2.93e+07" "RUA PEDRO MARCHI, 100" 13295000 "1.33e+07" "RUA ITAPETI, 500" 8693210 "8693210" "AVENIDA MAURO RAMOS, N. 275" 88020301 "8.80e+07" end
Comment