Consistency in number of digits
Dear All,
I apologise if this question is simple but I really can't figure it out.
In creating my chk file, I need to ensure that four of the variables contain a certain number of digits. I know this is normally controlled by number fields the .qes file. However, in this instance I need zeros to be included at the beginning (eg. 0003) so that all responses contain the same number of digits. This is because I will be putting these 4 variables together to create a 10 digit identifier later in the chk file.
At the moment, whenever I enter 0003, the zeros are removed and I am left with just 3.
Does anyone know if there is a way to ensure the zeros remain, and to ensure that each variable entered contains 4 digits?
Many thanks in advance for your advice!
Nicki
Nicki Bailey Centre Administrator Leonard Cheshire Disability and Inclusive Development Centre Department of Epidemiology and Public Health University College London 4 Taviton Street, London, WC1H 0BT, UK Tel: +44 (0) 207 679 5589 Fax: +44 (0) 207 388 2291 www.lcdisability.org/idc
Dear Nicki,
how will your identifier look like? Why doesn`t it work like this?
v1=2 v2=105 v3=27 v4=7
ident= v1*1000000000 + v2*1000000 + v3*1000 + v4 = 2105027007 (with 3 digits/variable)
Regards Juergen
epidata-list@lists.umanitoba.ca schrieb:
Dear All,
I apologise if this question is simple but I really can't figure it out.
In creating my chk file, I need to ensure that four of the variables contain a certain number of digits. I know this is normally controlled by number fields the .qes file. However, in this instance I need zeros to be included at the beginning (eg. 0003) so that all responses contain the same number of digits. This is because I will be putting these 4 variables together to create a 10 digit identifier later in the chk file.
At the moment, whenever I enter 0003, the zeros are removed and I am left with just 3.
Does anyone know if there is a way to ensure the zeros remain, and to ensure that each variable entered contains 4 digits?
Many thanks in advance for your advice!
Nicki
Nicki Bailey Centre Administrator Leonard Cheshire Disability and Inclusive Development Centre Department of Epidemiology and Public Health University College London 4 Taviton Street, London, WC1H 0BT, UK Tel: +44 (0) 207 679 5589 Fax: +44 (0) 207 388 2291 www.lcdisability.org/idc _______________________________________________ EpiData-list mailing list EpiData-list@lists.umanitoba.ca http://lists.umanitoba.ca/mailman/listinfo/epidata-list
Nicki: perhaps an idea would be to always make your identifiers text fields, even if they are numbers. If you nevertheless like to enter this particular field as a number, you could create a second field that takes the number and converts it into a text field with the desired leading zeros:
In the QES file:
vartxt ____ varnum ####
In the CHK file:
vartxt NOENTER END
varnum MUSTENTER AFTER ENTRY varntxt=varnum IF varnum<1000 THEN vartxt="0"+varnum ENDIF IF varnum<100 THEN vartxt="00"+varnum ENDIF IF varnum<10 THEN vartxt="000"+varnum ENDIF END END
Hans
epidata-list@lists.umanitoba.ca wrote:
<div class="moz-text-flowed" style="font-family: -moz-fixed">Dear All,
I apologise if this question is simple but I really can't figure it out.
In creating my chk file, I need to ensure that four of the variables contain a certain number of digits. I know this is normally controlled by number fields the .qes file. However, in this instance I need zeros to be included at the beginning (eg. 0003) so that all responses contain the same number of digits. This is because I will be putting these 4 variables together to create a 10 digit identifier later in the chk file.
At the moment, whenever I enter 0003, the zeros are removed and I am left with just 3.
Does anyone know if there is a way to ensure the zeros remain, and to ensure that each variable entered contains 4 digits?
Many thanks in advance for your advice!
Nicki
In most programming languages this (keeping leading zeros with a fixed format, say, four digits) is done with a print statement using a format string. For example, in Euphoria ( http://www.rapideuphoria.com/ ),
*Syntax:* printf(fn, st, x) *Description:* Print x, to file or device fn, using format string st. If x is a sequence, then format specifiers from st are matched with corresponding elements of x. If x is an atom, then normally st will contain just one format specifier and it will be applied to x, however if st contains multiple format specifiers, each one will be applied to the same value x. Thus printf() always takes exactly 3 arguments. Only the length of the last argument, containing the values to be printed, will vary. The basic format specifiers are:
%d - print an atom as a decimal integer %x - print an atom as a hexadecimal integer. Negative numbers are printed in two's complement, so -1 will print as FFFFFFFF %o - print an atom as an octal integer %s - print a sequence as a string of characters, or print an atom as a single character %e - print an atom as a floating-point number with exponential notation %f - print an atom as a floating-point number with a decimal point but no exponent %g - print an atom as a floating-point number using whichever format seems appropriate, given the magnitude of the number %% - print the '%' character itself
Field widths can be added to the basic formats, e.g. %5d, %8.2f, %10.4s. The number before the decimal point is the minimum field width to be used. The number after the decimal point is the precision to be used.
If the field width is negative, e.g. %-5d then the value will be left-justified within the field. Normally it will be right-justified. If the field width starts with a leading 0, e.g. %08d then leading zeros will be supplied to fill up the field. If the field width starts with a '+' e.g. %+7d then a plus sign will be printed for positive values.
But we don't have this in Epidata. So, unless you use a string field (text), you'll lose those leading zeros. My preference is to just generate (or use) a given unique ID and put the other data (region, area, etc.) in separate fields.
Pete Geddes
At the moment, whenever I enter 0003, the zeros are removed and I am left with just 3.
Does anyone know if there is a way to ensure the zeros remain, and to ensure that each variable entered contains 4 digits?
participants (1)
-
epidata-list@lists.umanitoba.ca