17
from CompareOUT_Visits as cmp, Deltas_Visits (keep=Site SubjectID VisitType c_:) as dlta
where cmp.Site=dlta.Site and cmp.SubjectID=dlta.SubjectID and
cmp.VisitType=dlta.VisitType and cmp._TYPE_='BASE';;
quit;
* If an indicator variable is flagged as a change (value of 1), output the
* corresponding variable and value to the Visits_bv dataset *;
data Visits_bv;
length varname $ 32 pre_value $ 64;
set Visits_prior_vals;
array changes_N(*) &CMPVARS_N; /* array to hold numeric variables in BASE row */
array changes_N_cnt(*) &CMPVARS_N_N; /* array of indicators for numeric variable changes */
array changes_C(*) &CMPVARS_C; /* array to hold character variables in BASE row */
array changes_C_cnt(*) &CMPVARS_C_N; /* array of indicators for character variable changes */
*Process the numeric variables*;
do i=1 to DIM(changes_N);
if changes_N_cnt(i) = 1 then do; /* if the indicator shows this variable has changed */
varname=vname(changes_N(i)); /* use the vname function to obtain the variable
name */
pre_value=put(changes_N(i),best.); /* place the formatted numeric value into
pre_value */
output; /* output a row for every variable involved in a change */
end;
end;
*Process the character variables;
do i=1 to DIM(changes_C);
if changes_C_cnt(i) = 1 then do; /*If the indicator shows this variable has changed */
varname=vname(changes_C(i)); /* use the vname function to obtain the variable
name */
pre_value=changes_C(i); /* place the character value pre_value */
output; /* output a row for every variable involved in a change */
end;
end;
keep Site SubjectID VisitType varname pre_value;
run;
* Find the after values for ID combinations with a difference;
* Select the rows from COMPARE in the PROC COMPARE output dataset that were found
* to have at least one difference. Include the character and numeric variables
* along with their change indicator variable from Delta_Visits;
proc sql;
create table Visits_post_vals as
select cmp.*, dlta.*
from CompareOUT_Visits as cmp, deltas_visits (keep=Site SubjectID VisitType c_:) as dlta
where cmp.Site=dlta.Site and cmp.SubjectID=dlta.SubjectID and
cmp.VisitType=dlta.VisitType and cmp._TYPE_='COMPARE';;
quit;
* If an indicator variable is flagged as a change (value of 1), output the
* corresponding variable and value to the Visits_bv dataset *;
data Visits_av;
length varname $ 32 post_value $ 64;
set Visits_post_vals;
array changes_N(*) &CMPVARS_N; /* array to hold numeric variables in COMP row */
array changes_N_cnt(*) &CMPVARS_N_N; /* array of indicators for numeric variable changes */
array changes_C(*) &CMPVARS_C; /* array to hold character variables in COMP row */
array changes_C_cnt(*) &CMPVARS_C_N; /* array of indicators for character variable changes */
*Process the numeric variables*;
do i=1 to DIM(changes_N);
if changes_N_cnt(i) = 1 then do; /* if the indicator shows this variable has changed */
varname=vname(changes_N(i)); /* use the vname function to obtain the variable
name */
post_value=put(changes_N(i),best.); /* place the formatted numeric value into
pre_value */
output; /* output a row for every variable involved in a change */
end;