how to sum numeric variables even if one of the variables is empty
Hello I would like to make an automatic sum (see: variable "daystotadm") of a series of variables (see: variable "daysadm1-2..."), but if only one of these variable is empty, the automatic calculation using the function SUM give a null result. Do anyone know a way to solve this problem without the need to enter a value for each variable. In my file I don not necessarily enter all the five lines and the number of days is already a calculated field? I attach the qes and the check files Thank you Francesco Grandesso
QES FILE ---------------------------------------------------------------------------------
Date of entry Date of exit Number of days -------------------------------------------- --------------- {dateentry1} <dd/mm/yyyy> {dateexit1} <dd/mm/yyyy> {daysadm1} ### {dateentry2} <dd/mm/yyyy> {dateexit2} <dd/mm/yyyy> {daysadm2} ### {dateentry3} <dd/mm/yyyy> {dateexit3} <dd/mm/yyyy> {daysadm3} ### {dateentry4} <dd/mm/yyyy> {dateexit4} <dd/mm/yyyy> {daysadm4} ### {dateentry5} <dd/mm/yyyy> {dateexit5} <dd/mm/yyyy> {daysadm5} ### -------------------------------------------- --------------- {daystotadm} Total days ####
CHK FILE ----------------------------------------------------------------------------------
dateexit1 AFTER ENTRY daysadm1=(dateexit1-dateentry1) daystotadm=SUM(daysadm1,daysadm2,daysadm3,daysadm4,daysadm5) END END
daysadm1 NOENTER END
.................... and so on for each of the five dateexit* and daysadm* variables
__________________________________________ Francesco Grandesso EPICENTRE 8, Rue Saint Sabin 75011 Paris, France tel +33 (0)1 4021 2847 fax +33 (0)1 4021 2803 email Francesco.GRANDESSO@epicentre.msf.org
Hi Francesco. Simplest way I could think of: Let's say you have 4 possible periods (entry1, exit1... Entry4 exit4): - Edit the CHK file with a text editor, and prepare some hidden variables which will help store intermediate calculations: BEFORE RECORD DEFINE NB1 #### DEFINE NB2 #### DEFINE NB3 #### DEFINE NB4 #### DEFINE tot1 ### DEFINE tot2 ### DEFINE tot3 ### DEFINE tot4 ### END
(nbX will store nomber of days for period X... ) (totX will store same number of days, or 0 if 1 of the fields is empty (nbX is empty)
Then, you will add the following check to each exit dates: D11 AFTER ENTRY NB1=ROUND(D11-D1) IF nb1 <> . THEN TOT1=nb1 ELSE tot1=0 ENDIF END END
(in the example, d1 is entry date of period 1 and d11 is exit date for same period). Note that NB1 and TOT1 hane not to appear on the entry form as they have been defined in the BEFORE RECORD check block) You can notice that there is a condition which returns zero to totx when nbx can't be calculated.
Last thing to do is to sum up all the TOTx (in the last date check block): d41 AFTER ENTRY NB4=ROUND(D41-D4) IF nb4 <> . THEN TOT4=nb4 ELSE tot4=0 ENDIF totd=sum(tot1,tot2,tot3,tot4) END END
(D41 if the last exit date to be entered).
Il y a peut-être plus simple, mais ça marche! Bon courage!
______________________________________________ Gilles DELMAS Institut de Veille Sanitaire Dept. Maladies Infectieuses, Unité infections entériques, alimentaires et zoonoses 12 rue du Val d'Osne 94415 Saint-Maurice cedex - France + 33 1 41 79 67 27 g.delmas@invs.sante.fr ______________________________________________
-----Message d'origine----- De : epidata-list@lists.umanitoba.ca [mailto:epidata-list@lists.umanitoba.ca] Envoyé : vendredi 3 août 2007 17:36 À : epidata-list@lists.umanitoba.ca Objet : [EpiData-list] how to sum numeric variables even if one of thevariables is empty
Hello I would like to make an automatic sum (see: variable "daystotadm") of a series of variables (see: variable "daysadm1-2..."), but if only one of these variable is empty, the automatic calculation using the function SUM give a null result. Do anyone know a way to solve this problem without the need to enter a value for each variable. In my file I don not necessarily enter all the five lines and the number of days is already a calculated field? I attach the qes and the check files Thank you Francesco Grandesso
QES FILE ---------------------------------------------------------------------------------
Date of entry Date of exit Number of days -------------------------------------------- --------------- {dateentry1} <dd/mm/yyyy> {dateexit1} <dd/mm/yyyy> {daysadm1} ### {dateentry2} <dd/mm/yyyy> {dateexit2} <dd/mm/yyyy> {daysadm2} ### {dateentry3} <dd/mm/yyyy> {dateexit3} <dd/mm/yyyy> {daysadm3} ### {dateentry4} <dd/mm/yyyy> {dateexit4} <dd/mm/yyyy> {daysadm4} ### {dateentry5} <dd/mm/yyyy> {dateexit5} <dd/mm/yyyy> {daysadm5} ### -------------------------------------------- --------------- {daystotadm} Total days ####
CHK FILE ----------------------------------------------------------------------------------
dateexit1 AFTER ENTRY daysadm1=(dateexit1-dateentry1) daystotadm=SUM(daysadm1,daysadm2,daysadm3,daysadm4,daysadm5) END END
daysadm1 NOENTER END
.................... and so on for each of the five dateexit* and daysadm* variables
__________________________________________ Francesco Grandesso EPICENTRE 8, Rue Saint Sabin 75011 Paris, France tel +33 (0)1 4021 2847 fax +33 (0)1 4021 2803 email Francesco.GRANDESSO@epicentre.msf.org
participants (1)
-
epidata-list@lists.umanitoba.ca