# [EpiData-list] Re: EpiData-list Digest, Vol 67, Issue 6

epidata-list at lists.umanitoba.ca epidata-list at lists.umanitoba.ca
Tue May 19 21:48:57 CDT 2009

```Just use the STRING function once. It should be

AFTER ENTRY
MEMID=STRING(LOCALITY*1000000000 + VILLAGECOD*1000000 + HHOLDCODE*100 +
MEMBERNO)
END

For your example:
LOCALITY = 1 (must be 1 digit)
VILLAGECOD = 023 (must be 3 digits)
HHOLDCODE = 0014 (must be 4 digits)
MEMBERNO = 12 (must be 2 digits)

The addition inside the STRING(...) becomes

1000000000 1*1000000000  (add 9 zeros)
23000000 023*1000000   (add 6 zeros)
1400 0014*100      (add 2 zeros)
12 12
----------
1023001412 add up the numbers

I prefer to do the math this way:
(((locality*1000+villagecod)*10000+hholdcode)*100+memberno

locality * 1000 because villagecod has 3 digits, then add villagecod
then *10000 because hholdcode has 4 digits, then add hholdcode
then *100 because memberno has 2 digits, then add memberno

If you have more than 1 digit in the leading code (say locality could be
01 to 99), then you have to account for the leading zero there as well.
If locality had two digits and range 1 to 99,  you need an 11-digit id
and you do this:

memid =
copy(string((((100+locality)*1000+villagecod)*10000+hholdcode)*100+memberno),2,11)

The math creates the string "101023001412" and the copy function gets
rid of the leading 1, leaving "01023001412"

Jamie

Nicki wrote:
> Juergen, I tried to include what you suggested within the brackets but
> in this case, the MEMID simply didn't appear. This is how it looked:
>
> MEMBERNO
>   RANGE 0 99
>   MUSTENTER
>   AFTER ENTRY
>     LET
> MEMID=String(LOCALITY*1000000000)+String(VILLAGECOD*1000000)+String(HHOLDCODE*1000)+String(MEMBERNO)
>
>   END
> END
>
> Any ideas why this didn't work?

```

More information about the EpiData-list mailing list