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

Hey all, I have a database with ID numbers and a variable called Type_Of_Visit. If any patient (denoted by variable ID) has a Type_Of_Visit as "inpatient" then I need to tag that ID as 1 and the remaining IDs without any inpatient as 0.

 

The issue is each ID can have multiple types of visits like Emergency, Outpatient, inpatient, multiple outpatient, multiple Emergency and multiple inpatient, and any combination of these, etc. All I want to do is to create a new variable Inpatient_Count if that ID has an inpatient visit at any time (it does not matter if the same ID has other types of visits). If that ID has at least one inpatient encounter, I want to tag all entries for that ID as 1 (in the new variable), and rest of the IDs without inpatient encounter as 0. Hope I clarified it! Please let me know if need further clarification.

 

Thanks for the help in advance!

 

Here is what I want:

ID            Type_Of_Visit     Inpatient_Count

1              inpatient                 1

1              Emergency             1

1              Outpatient              1

2              inpatient                  1

2             inpatient                   1

2             inpatient                   1

3           outpatient                   0

3           outpatient                    0

3           Emergency                   0

4          Emergency                  0

5          Outpatient                    0

6           inpatient                     1

6            Emergency                 1

7           Outpatient                     0

7              Outpatient                  0

7           Emergency                   0

7           Emergency                   0

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26
/* UNTESTED CODE */

data count_inpatient;
    set have;
    if upcase(type_of_visit)='INPATIENT' then new_inpatient_variable=1;
    else new_inpatient_variable=0;
run;

proc summary nway data=count_inpatient;
    class id;
    var new_inpatient_variable;
    output out=count_inpatient1 max=;
run;

data count_inpatient2;
    merge count_inpatient(drop=new_inpatient_variable) count_inpatient1;
    by id;
run;
--
Paige Miller

View solution in original post

3 REPLIES 3
PaigeMiller
Diamond | Level 26
/* UNTESTED CODE */

data count_inpatient;
    set have;
    if upcase(type_of_visit)='INPATIENT' then new_inpatient_variable=1;
    else new_inpatient_variable=0;
run;

proc summary nway data=count_inpatient;
    class id;
    var new_inpatient_variable;
    output out=count_inpatient1 max=;
run;

data count_inpatient2;
    merge count_inpatient(drop=new_inpatient_variable) count_inpatient1;
    by id;
run;
--
Paige Miller
sms1891
Quartz | Level 8

Thank you!

sasfy
Calcite | Level 5

 

 

proc sort data=have out=inp nodupkey;

by ID Type_of_visit;

where upcase(TYPE_OF_VISIT)='INPATIENT';

run;

 

data get;

merge have inp;

by ID;

run;

 

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 3 replies
  • 447 views
  • 0 likes
  • 3 in conversation