## Combine Multiple Variables in SAS

Regular Contributor
Posts: 150

# Combine Multiple Variables in SAS

I am working on a short retention calendar for a study. I have 5 visits and 4 identical variables. The Variables are set up like this:

v2status-v5status

1=interview completed

2=Due for Interview

3=Not due for interview

4=30 days past due

5=3 months past due

Basically what I want to do is create a new variable that combines all of the variables to show which interview a participant is currently due for with the following categories:

1=12 month

2=18 month

3=24 month

4=completed study

I started writing the code in its most simple form, the problem is there is a combination of possible outcomes because a participant would have missed visit 2 but completed visit 3  and missed visit 4, etc..Participants can no longer complete visit 2. Give the original variable v2status-v5status, is there an easy way to figure out all possible combinations of variables so I can write the code to take them into account? The code I have now only takes into account perfect retention and takes into account about half of the actual data. Any help is greatly appreciated as I would prefer no to write 100 lines of code for this one variable and all different combinations.

if v2status in (1) and v3status in (1) and v4status in (1) and v5status in (1) then visit_num=5; ***Completed the study;

else if v5status in (1) then visit_num=5;***Completed the study;

else if v2status in (1) and v3status in (1) and v4status in (1) and v5status in (2,4,5) then visit_num=3; ***Due for 24 month visit;

else if v2status in (1) and v3status in (1) and v4status in (2,4,5)  then visit_num=2; **Due for 18 month visit;

else if v2status in (1) and v3status in (2,4,5)   then visit_num=1; ***Due for 12 month visit;

Super User
Posts: 23,700

## Re: Combine Multiple Variables in SAS

Wouldn't you only be interested in the last non-missing data point then?

Can you post some sample data with expected output?

Regular Contributor
Posts: 150

## Re: Combine Multiple Variables in SAS

None of them will have missing data because these variables are figured out based on the time since their baseline visit and specific dates.

I am attaching some data that I created that is similar to what I am looking at. I can't post actual data because of IRB protocols, etc...I wasn't sure how to post an excel file so the data is below

The expected output would be a variable that tells me who is currently due and for what visit. I will use ODS output and proc print to create a listing in word. I hope this helps clarify.

 ID v3status v4status v5status v2status A23 5 5 5 5 A24 5 5 5 5 A25 5 5 4 5 A26 5 5 4 5 A27 5 5 4 5 A28 5 5 4 5 A29 5 5 4 5 A55 5 5 2 5 A56 5 5 2 5 A57 5 5 2 5 A58 5 5 2 5 A59 5 5 2 5 A79 5 5 3 5 A80 5 5 3 5 A81 5 5 3 5 A82 5 5 3 5 A83 5 5 3 5 A84 5 4 3 5 A85 5 4 3 5 A86 5 4 3 5 A87 5 4 3 5 A88 5 4 3 5 A89 5 4 3 5 A90 5 4 3 5 A91 5 4 3 5 A92 5 4 3 5 A176 4 2 3 1 A177 2 3 3 5 A178 4 2 3 1 A179 2 3 3 5 A180 4 2 3 1 A181 2 3 3 5 A182 2 3 3 5 A183 2 3 3 5 A184 1 4 4 1 A185 1 4 3 1 A186 1 4 2 1 A187 2 3 3 5 A188 2 3 3 5 A189 2 3 3 5 A191 2 3 3 5 A192 2 3 3 5 A193 4 3 3 1 A194 3 3 3 4 A195 3 3 3 4 A196 1 1 5 1 A197 1 1 5 1 A198 1 4 3 1 A199 4 3 3 1 A478 1 1 1 1 A479 1 1 1 1 A480 1 1 1 1 A481 1 1 1 1 A482 1 1 1 1 A483 4 1 1 1 A484 4 1 1 4 A485 4 4 1 4 A486 4 1 1 1 A487 1 1 1 1 A488 4 4 1 4 A489 1 1 1 1 A490 1 1 1 1 A491 1 1 1 1 A492 1 1 1 4
Super User
Posts: 23,700

## Re: Combine Multiple Variables in SAS

Expected output? I'd rather have only 5 or 6 lines of data with the expected output.

Regular Contributor
Posts: 150

## Re: Combine Multiple Variables in SAS

Ok. Here is the expected output and below is the sample data that would produce this expected output. Let me know if you need more information.

Expected output.

ID            Visit Due

A188     Visit 3

A189     Visit 5

A191     Visit 4

A192     Visit 3

A193     Visit 3

A194     Visit 3

A195     Visit 4

 ID v3status v4status v5status v2status
 A188 2 3 3 5 A189 5 5 2 5 A191 5 2 3 5 A192 2 3 3 5 A193 4 3 3 1 A194 3 3 3 4 A195 5 4 3 4
Super User
Posts: 10,770