BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
mdeber30
Fluorite | Level 6

Hi everybody


I start on SAS and I want to detect the impact of a new positif test in the following data and fill the impact variable in this way  :

image.JPG

In fact we count a new impact of positive test if the test was positive a the first time of follow-up period or negative at the precedent time. I have found how sort the data by patient number and by follow-up time. I hope my  explanations are clear ...

 

Thank you for your help.

 

Marilyn

 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26
data want;
    set have;
    by patient;
    prev_test=lag(test);
    if (first.patient and test='Positif') 
        or (not first.patient and test='Positif' and prev_test='Negatif') then incidence=1;
    else incidence=0;
    drop prev_test;
run;
--
Paige Miller

View solution in original post

9 REPLIES 9
PaigeMiller
Diamond | Level 26
data want;
    set have;
    by patient;
    prev_test=lag(test);
    if (first.patient and test='Positif') 
        or (not first.patient and test='Positif' and prev_test='Negatif') then incidence=1;
    else incidence=0;
    drop prev_test;
run;
--
Paige Miller
mdeber30
Fluorite | Level 6

Hi,

Thanks for your help, it's work but I have a new problem :image2.JPG

I want to replace the missing values in Tt if the Visit isn't M00 by the Tt at the next visit. For example at visit M03-M06 I want to put 2 in the variable Tt. Is it possible ?

 

Thanks for your help

 

Marilyn

PaigeMiller
Diamond | Level 26

Sure its possible. But I would need a better explanation and a few more examples, because I don't seem to understand what you wrote.

--
Paige Miller
mdeber30
Fluorite | Level 6

I send you a new example. For each patient, at M00 the traitment is missing it's normal because the patient haven't traitment before.

 

But if the visits are not M00, M03,M06, M09 ... but tests between two visits as M06-M09 or M9-M12 or M3-M6. We must have the traitment the patient have indicate taked at the next visit (because we don't know the traitment actually taken). The patient indicate the traitment taked at visits M09, M12 and M9 in this case).

 

 

image2.JPG

 

I want to have this result

 

image3.JPG

 

For test at M06-M09 I put the value of M09 it's the next visit, for test at M09-M12, I put the value of M12 visit and for the test at M03-M06 I put the value of traitment of M12 visit because it's the next visit ...

I hope it's clear ...

 

Thanks for your help

 

Marilyn

PaigeMiller
Diamond | Level 26

Why does M09-M12 for Patient 1 go back to treatment 1?

 

I realize you are new here, so please help us out. We cannot really write code on data that is in screen captures. We need working SAS data step code in order to work on your data. You can type in the SAS data step code yourself or follow these instructions. Do not attach files, do not use screen captures to share with us your data.

--
Paige Miller
mdeber30
Fluorite | Level 6
Hi
It's fictives data here because I can't send reals datas. To resume I have patients with ou without impact of infection at a specific visit (M00, M03 ...). At each visit a treatment is prescribed (continue or at demand) but we know exactly the traitment used at the next visit. When we have a new impact of infection we want to know which traitment the patient have followed. But when the test realised between two visit for example M03-M06 whe know the prescribed traitment but not the real followed traitment which is know at the next visit.
Is it more clear ?
Marilyn
PaigeMiller
Diamond | Level 26

@mdeber30 wrote:

It's fictives data here because I can't send reals datas.

Fake data is fine. You need to provide the fake data as SAS data step code, as I explained. I am not going to try to work from a screen capture of fake data.

--
Paige Miller
mdeber30
Fluorite | Level 6
Hi
Ok I understand now. I'll do it !
Marilyn
mdeber30
Fluorite | Level 6
data dataset;
length id_patient $ 7;
length visit $ 7;
input id_patient $ visit $ traitment time;
datalines;
Patient1 M00 . 0
Patient1 M03 1 90
Patient1 M06 1 180
Patient1 M06-M09 . 250
Patient1 M09 2 270
Patient1 M09-M12 . 290
Patient1 M09-M12 . 95
Patient1 M12 1 360
Patient1 M15 1 450
Patient2 M00 . 0 
Patient2 M03 2 90
Patient2 M03-M06 . 125
Patient2 M09 2 270
Patient2 M12 1 360
;
run;

Hi here the SAS code for the dataset

Thanks for your help

Marilyn

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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
  • 9 replies
  • 799 views
  • 2 likes
  • 2 in conversation