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

Hello,everyone,

I am a green hand of SAS,and I appreciate very much your kindly help.

My data is as below,each subject has multiple visit.Time is the time length compared to the last visit,total time is the time length compared to the first visit.Stage=0 is no disease and stage=1 is diagnosed with disease.I want to compute the disease free time.For example,for the first patient,the disease free time(variable:length) is 13,since he was first diagnosed at the third visit,and by that time,13 months passed.For the second subject,should be 8 months since he was diagnosed at the second visit ,so at the third visit,the disease free time should still be 8 months.But my output is not correctly for the situation like the second subject.

Thanks!

  Obs    id      treatment      visit    time    stage    totalm

      1     1    control group      1        0       0         0
      2     1    control group      2        4       0         4
      3     1    control group      3        9       1        13
      4     2    control group      1        0       0         0
      5     2    control group      2        8       1         8
      6     2    control group      3        4       1        12
      7     3    control group      1        0       0         0
      8     3    control group      2        5       0         5
      9     3    control group      3        5       0        10
     10     3    control group      4        9       0        19
     11     4    control group      1        0       0         0

coding:

data hw9;

set hw9;

by id visit;

retain length;

if first.id then length=0;

if stage=1 then length=totalm;

/*if stage=1 then length=length;*/

if last.id and stage=0 then length=totalm;

/*if last.id then output;*/

run;

proc print data=hw9;

run;

output:


  Obs   id     treatment     visit   time   stage   totalm   length

    1    1   control group     1       0      0        0        0
    2    1   control group     2       4      0        4        0
    3    1   control group     3       9      1       13       13
    4    2   control group     1       0      0        0        0
    5    2   control group     2       8      1        8        8
    6    2   control group     3       4      1       12       12
    7    3   control group     1       0      0        0        0
    8    3   control group     2       5      0        5        0
    9    3   control group     3       5      0       10        0
   10    3   control group     4       9      0       19       19

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

Is the following what you are trying to accomplish?:

data hw9;

  informat treatment $20.;

  input  id   treatment &     visit    time    stage    totalm;

  cards;

1    control group      1        0       0         0

1    control group      2        4       0         4

1    control group      3        9       1        13

2    control group      1        0       0         0

2    control group      2        8       1         8

2    control group      3        4       1        12

3    control group      1        0       0         0

3    control group      2        5       0         5

3    control group      3        5       0        10

3    control group      4        9       0        19

4    control group      1        0       0         0

;

data hw9;

  set hw9;

  by id visit;

  retain length start;

  if first.id then do;

    length=0;

    start=0;

  end;

  if stage=1 and start=0 then do;

    length=totalm;

    start=1;

  end;

  /*if stage=1 then length=length;*/

  if last.id and stage=0 then length=totalm;

  /*if last.id then output;*/

run;

proc print data=hw9;

run;

View solution in original post

7 REPLIES 7
art297
Opal | Level 21

Is the following what you are trying to accomplish?:

data hw9;

  informat treatment $20.;

  input  id   treatment &     visit    time    stage    totalm;

  cards;

1    control group      1        0       0         0

1    control group      2        4       0         4

1    control group      3        9       1        13

2    control group      1        0       0         0

2    control group      2        8       1         8

2    control group      3        4       1        12

3    control group      1        0       0         0

3    control group      2        5       0         5

3    control group      3        5       0        10

3    control group      4        9       0        19

4    control group      1        0       0         0

;

data hw9;

  set hw9;

  by id visit;

  retain length start;

  if first.id then do;

    length=0;

    start=0;

  end;

  if stage=1 and start=0 then do;

    length=totalm;

    start=1;

  end;

  /*if stage=1 then length=length;*/

  if last.id and stage=0 then length=totalm;

  /*if last.id then output;*/

run;

proc print data=hw9;

run;

jing2000yr
Calcite | Level 5

No.I want to add a new variable length which represent disease free time length,like the lower part 'output' in which the variable length is not computed correctly for subject id 2,since he got the disease at the second visit,the disease free time should be 8 months.Then his third visit,the disease free time should still be 8 months,but my coding output 12 months.

The variable time is the time length compared the former visit,like visit2 compared to visit 1,and visit 3 compared to visit 2.The totalm is the time length compared to the first visit,like visit 2 compare to 1,visit 3 compared to 1.

Thank you!

jing2000yr
Calcite | Level 5

Dear Arthur,

Oh...Thank you so so much!

It works!!!

Jing

art297
Opal | Level 21

Jing: Then mark the question as answered so that others won't spend time trying to come up with a solution.

jing2000yr
Calcite | Level 5

Dear Arthur,

It is my first time entering this forum.I did not see the tab with which I can mark the question as answered.Sorry,I am trying.

art297
Opal | Level 21

If you click on my response there will be an icon there that you can click indicating that it is a correct answer.

Nothing to be sorry about but, if one doesn't take that action, a number of people will still try to provide an answer.

jing2000yr
Calcite | Level 5

Thank you,Arthur.It is weird that I can not do this in the Windows system set up in virtual box in my Mac.But when I open the website in Mac itself,I saw the obvious tab to mark the right answer...

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
  • 7 replies
  • 692 views
  • 1 like
  • 2 in conversation