Dear SAS Help,
In the data below, I want to calculate cd4 changes within a specific interval date '12-month' from the first test.
Any help, I much appreciate. Thanks in advance.
Ps
Obs id CD4COUNT CD4DATE cd4 cd4date last_cd4 cd4date 12month cd4
1 20 332 29MAY2006 332 29MAY2006 6 03NOV2009 29MAY2007 326
2 20 267 12JUN2006 332 29MAY2006 6 03NOV2009 29MAY2007 326
3 20 207 05DEC2006 332 29MAY2006 6 03NOV2009 29MAY2007 326
4 20 71 20NOV2007 332 29MAY2006 6 03NOV2009 29MAY2007 326
5 20 15 24JUN2008 332 29MAY2006 6 03NOV2009 29MAY2007 326
6 20 8 07AUG2008 332 29MAY2006 6 03NOV2009 29MAY2007 326
7 20 3 02JUN2009 332 29MAY2006 6 03NOV2009 29MAY2007 326
8 20 6 03NOV2009 332 29MAY2006 6 03NOV2009 29MAY2007 326
9 40 20 30JAN2003 20 30JAN2003 326 14DEC2010 30JAN2004 -306
10 40 10 13MAR2003 20 30JAN2003 326 14DEC2010 30JAN2004 -306
11 40 300 08MAY2003 20 30JAN2003 326 14DEC2010 30JAN2004 -306
12 40 239 19JUN2003 20 30JAN2003 326 14DEC2010 30JAN2004 -306
Hi! Try this way :
proc sort data=have; by id CD4DATE; run;
data want;
do until(last.id);
set have; by id;
if first.id then do;
firstDate = CD4DATE;
firstCD4 = CD4COUNT;
end;
else do;
delay = abs(intck("DAY", firstDate, CD4DATE) - 365);
minDelay = min(delay, minDelay);
if minDelay = delay then do;
yearCD4 = CD4COUNT;
lastDate = CD4DATE;
end;
end;
end;
format firstDate lastDate date9.;
keep id firstDate firstCD4 yearCD4 lastDate;
run;
proc print; run;
PG
Based on your example, what do you want the resulting dataset to look like?
Dear Sir,
I am relatively new with longitudinal analysis, but this is part of study. I want the resulting in long format as I will study change in cd4 in relationship with initial antiretroviral class.
Sincerely,
Ps
Understood, but for any of us to help, we have to see want you want to achieve. It would also be useful to see what you have already tried to accompomplish what you want.
Dear Sir,
For instance, id 20, I want to calculate a difference between cd4=332 (first date) and cd4=71 (20Nov2007) in which this date is the nearest one year after the first test.
Also, id 40, a difference between cd4=20 (30Jan2003) and cd4=239 (19Jun2003) that the date is nearest one year after the first test.
Thanks.
Ps
Hi! Try this way :
proc sort data=have; by id CD4DATE; run;
data want;
do until(last.id);
set have; by id;
if first.id then do;
firstDate = CD4DATE;
firstCD4 = CD4COUNT;
end;
else do;
delay = abs(intck("DAY", firstDate, CD4DATE) - 365);
minDelay = min(delay, minDelay);
if minDelay = delay then do;
yearCD4 = CD4COUNT;
lastDate = CD4DATE;
end;
end;
end;
format firstDate lastDate date9.;
keep id firstDate firstCD4 yearCD4 lastDate;
run;
proc print; run;
PG
Dear Sir,
I greatly appreciate and thank you very much for your time in helping me this task. I ran the analysis and checked results that are exactly I am looking for.
Again thanks,
Sincerely,
Ps
Please mark your question as answered and gave PG and Art credits for helping you. If you don't know how to mark your question as answered please ask. Thank you!
Dear Linlin,
I appreciate your friendly reminding me. Please tell me as I am relative new for the community. I am not sure where I can give a mark.
I look forward to hearing from you soon.
Ps
Hi Linlin,
I just clicked correct answer. Am I doing the right way?
Ps
Yes!
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.