Output difference between set expression and if loop
Hi All,
I have the following problem. I try to calculate the average number of secondary diagnoses in the patients, who are still staying in the hospital. Some of them do have a secondary diagnosis or two, some does not have any yet. I have to take all in-patients and all existing secondary diagnoses by these patients into account and calculate a mean value per patient per department.
The data model looks as follows:
let vMaxDate = num(today()) - 30;
let vMinDate = $(vMaxDate) – 200;
Dep:
LOAD * INLINE [
Units
Surgery
Angiology
Traumatology
Obstetrics
Nephrology
];
Let vDepCount=FieldValueCount('Units');
Diagnosis:
LOAD * INLINE [
Code
J10
K20
L30
M40
N50
];
let vDiagCount = FieldValueCount('Code');
for i = $(vMinDate) to $(vMaxDate)
let vAttDate = $(i);
let vDuration = Round(Rand() * (25 - 1 ) + 1, 1);
IF rand() > 0.3 THEN
let vDisDate =$(vAttDate) + $(vDuration);
ELSE
vDisDate =;
let vDuration = $(vMaxDate) - $(vAttDate);
END IF
for j = 0 to $(vDepCount) - 1
let vThisDep = Peek('Units', $(j), 'Dep');
let vN = $(i)* 1000 + $(j) + 100001; // Patient-ID.
Patients: load '$(vN)' as PATID, date('$(vAttDate)') as AttDate, date('$(vDisDate)') as DisDate, $(vDuration) as Duration, '$(vThisDep)' as DEP
autogenerate(1);
IF rand() > 0.5 THEN
for k = 1 to 3
let vD = floor(rand() * ($(vDiagCount)));
ICD:
load '$(vN)' as PATID, peek('Code', $(vD), 'Diagnosis') as ICDCODE, 'SEC' as ICDTYPE autogenerate (1);
next k;
END IF;
next j;
next i;
drop tables Dep, Diagnosis;
vDepCount=;
vDiagCount=;
vDatesCount=;
i=;
vAttDate=;
vDuration=;
i=;
j=;
vThisDep=;
vN=;
vD=;
k=;
vDisDate=;
vMaxDate=;
vMinDate=;
This set expression however seems to calculate the average only on the patients who does have at least one secondary diagnosis (thus exclude those who does not have any):