I need to calculate the weight differential across doctor visits for 25 unique patients with varying numbers of visits 1-4. I thought transposing the data with an array and an if do statement assignment statements to calculate the weight differential was the way to go (have not done this yet since data not aligning correct). I'm having a problem reading the data i.e. data for patient Y has data from patient X because X only had 3 visits instead of 4.
Have 2 questions, is this the best approach to calculate the weight differential by patient and what is the treatment for varying visits by patient.
Data clinincal2;
input Patient visit date date9. weight gender $ group $;
CARDS;
1 1 26mar2007 157 male C
1 2 30jun2007 165 male C
1 3 08aug2007 162 male C
2 1 05jun2008 160 female D
3 1 01jan2007 154 female D
3 2 06feb2007 152 female D
3 3 01jun2007 140 female D
3 4 01aug2007 138 female D
4 1 12mar2007 195 male C
4 2 12jun2007 190 male C
5 1 30apr2007 185 female C
;
Data clinical3;
set clinical2;
by patient;
array visits (4) V1-V4;
if first.patient then i = 1;
visits [i] = Weight;
if last.patient then output;
i + 1;
retain V1-V4;
drop i;
RUN
You are turning an easy problem into a difficult one. In the long run, you must Must MUST learn to program with data in its original form (as illustrated in your data set CLINICAL2). Assuming the observations are in the proper order:
data want;
set clinical2;
by patient;
weight_dif = dif(weight);
if first.patient then weight_dif = .;
run;
This gives you visit-by-visit differences. If you want the difference from the first visit, the tools are similar:
data want;
set clinical2;
by patient;
if first.patient then baseline_weight = weight;
retain baseline_weight;
weight_dif = weight - baseline_weight;
run;
You are turning an easy problem into a difficult one. In the long run, you must Must MUST learn to program with data in its original form (as illustrated in your data set CLINICAL2). Assuming the observations are in the proper order:
data want;
set clinical2;
by patient;
weight_dif = dif(weight);
if first.patient then weight_dif = .;
run;
This gives you visit-by-visit differences. If you want the difference from the first visit, the tools are similar:
data want;
set clinical2;
by patient;
if first.patient then baseline_weight = weight;
retain baseline_weight;
weight_dif = weight - baseline_weight;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.