BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
RickyS
Quartz | Level 8

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

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

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;

View solution in original post

1 REPLY 1
Astounding
PROC Star

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;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 576 views
  • 2 likes
  • 2 in conversation