BookmarkSubscribeRSS Feed
amrodri
Calcite | Level 5

Hello I am not sure if someone could help me with the following:


I have a longitudinal dataset of a binary variable that  is equal to 1 when there is an infection in a patient, otherwise it is 0. Sometimes infections persist for seveal visits, sometimes they only remain for one visit and the patient is cured.I want to create 3 variables (X!, X2, X3) that would indicate a 1 or a 0 according to the following criteria:


In other words, this is how is might look and what I which to have my program do:

ID visit1  visit2  visit3  visit4      VARIABLE X1     VARIABLE X2         VARIABLE X3

1     0      0          0          0               0                              0                              0

2     0      1          0          0               0                              1                              0    

3     1     1           0          0               1                              1                              0

4     0      1          1          1                1                              1                             1

5    0       1          0          1               0                               1                              0


X1) Variable is = 1 when there is an infection for At least two or more consecutive visits per patient.

X2) Variable is = 1 when there is an infection for At least one visits per patient (Any infection).

X3) Variable is = 1 when there is an infection for At least three or more consecutive visits per patient.

Anyone can help me? I do not know how to solve this.


Thank youse

4 REPLIES 4
data_null__
Jade | Level 19

Something like this perhaps.

data visit;
   input id v1-v4;
   length r $4;
   r=cats(of v:);
   x1=not not find(r,
'11');
   x2=not not find(r,'1');
   x3=not not find(r,'111');
   cards;
1 0 0 0 0
2 0 1 0 0
3 1 1 0 0
4 0 1 1 1
5 0 1 0 1
;;;;
   run;
proc print;
  
run;
RamKumar
Fluorite | Level 6

How does 'not not find' works here? Is it a function by any chance?

data_null__
Jade | Level 19

NOT is a Boolean operator, in this case NOT NOT turns the position returned by FIND into 1 or ZERO making a Boolean of it.

Haikuo
Onyx | Level 15

Or to use parenthesis to get the Boolean:  x1=(find(r,'11')>0);

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1533 views
  • 1 like
  • 4 in conversation