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

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

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

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

PG

View solution in original post

10 REPLIES 10
art297
Opal | Level 21

Based on your example, what do you want the resulting dataset to look like?

PhanS
Obsidian | Level 7

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

art297
Opal | Level 21

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.

PhanS
Obsidian | Level 7

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

PGStats
Opal | Level 21

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

PG
PhanS
Obsidian | Level 7

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

Linlin
Lapis Lazuli | Level 10

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!

PhanS
Obsidian | Level 7

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

PhanS
Obsidian | Level 7

Hi Linlin,

I just clicked correct answer. Am I doing the right way?

Ps

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
  • 10 replies
  • 1112 views
  • 9 likes
  • 4 in conversation