Jump to content

Merge and aggregate datasets: Difference between revisions

Harbour: use a value of -999 for missing scores
(Harbour: use a value of -999 for missing scores)
Line 798:
 
=={{header|Harbour}}==
 
Harbour does not have special values for NA or NaN, and missing numerical values are represented as zeros. In the following, we have used -999 for missing scores.
 
<syntaxhighlight lang="xbase">
&& SQL-like INSERT command (note the variable number of arguments)
#xcommand INSERT INTO <table> ( <uField1>[, <uFieldN> ] ) VALUE ( <uVal1>[, <uValN> ] ) => ;
<table>->(dbAppend()); <table>-><uField1> := <uVal1> [; <table>-><uFieldN> := <uValN>]
Line 827 ⟶ 828:
vStruct := {{"patient_id", "n", 8, 0}, {"visit_date", "d", 10, 0}, {"score", "n", 8, 1}}
dbCreate( "visit", vStruct,, .T., "visit" )
INSERT INTO visit (patient_id, visit_date, score) VALUES (2002, ctod("2020-09-10"), 6.8), ;
INSERT INTO visit (patient_id1001, visit_datectod("2020-09-17"), score5.5) VALUES, (10014004, ctod("2020-09-1724"), 58.54), ;
INSERT INTO visit (patient_id2002, visit_datectod("2020-10-08"), score-999) VALUES, (40041001, ctod("20201900-0901-2401"), 86.46), ;
INSERT INTO visit (patient_id3003, visit_datectod("2020-11-12"), VALUES-999), (20024004, ctod("2020-1011-0805"), 7.0), ;
INSERT INTO visit (patient_id, visit_date, score) VALUES (1001, ctod("2020-11-19"), 5.3)
INSERT INTO visit (patient_id, score) VALUES (1001, 6.6)
INSERT INTO visit (patient_id, visit_date) VALUES (3003, ctod("2020-11-12"))
INSERT INTO visit (patient_id, visit_date, score) VALUES (4004, ctod("2020-11-05"), 7.0)
INSERT INTO visit (patient_id, visit_date, score) VALUES (1001, ctod("2020-11-19"), 5.3)
INDEX ON patient_id TO visit_id
 
Line 846 ⟶ 844:
DO WHILE ! Eof()
xCurId := patient_id && grouping variable
aAgg := {0, 0, 0.0, ctod("190001011900-01-01")} && initial values
DO WHILE ! Eof() .AND. xCurId == patient_id
aAgg := {1+aAgg[1], iif(score==0.0-999,aAgg[2],1+aAgg[2]), score+aAgg[3], max(visit_date, aAgg[4])} && update;
iif(score==-999, aAgg[3], score+aAgg[3]), max(visit_date, aAgg[4])} && update
SKIP
ENDDO
136

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.