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

Hello,

 

I'm a novice SAS user (SAS 9.4) and I'm working with a healthcare dataset where I need to count the number of observations that occurred on the same date at different places of service. Example, if ID 1 was seen at the ED on 01/01/2020 and Inpatient on 01/01/2020 then the new variable would count that as 1 service but if ID 1 was seen at the ED on 01/01/2020 and Inpatient on 01/31/2020 then the new variable wouldn't count that. How would I create a variable that would count that?

 

 

 

data test;
input id $ date yymmdd10. place $3. ;
format date yymmdd10.;
datalines;
1 2020/09/10 ED
1 2020/09/10 IN
2 2020/10/10 IN
3 2020/04/03 ED
3 2020/05/03 ED
3 2020/05/29 IN
4 2020/10/10 IN
4 2020/10/10 ED
4 2020/11/03 ED
4 2020/12/29 IN
;
run;

 

 

My expected output would be something like this:

IDDATEPLACENEWVAR
19/10/2020ED1
19/10/2020IN1
210/10/2020IN.
34/3/2020ED.
35/3/2020ED.
35/29/2020IN.
410/10/2020IN1
410/10/2020ED1
411/3/2020ED.
412/29/2020IN.

 

I would really appreciate any insight. Thank you!

 

Amanda

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

Try this

 

proc sql;
   create table want as
   select *
        , (count (distinct place) > 1) as newvar
   from test
   group by ID, date
   ;
quit;

View solution in original post

4 REPLIES 4
aokolo
Fluorite | Level 6

Hello,

My expected output would be:

IDDATEPLACENEWVAR
19/10/2020ED1
19/10/2020IN1
210/10/2020IN.
34/3/2020ED.
35/3/2020ED.
35/29/2020IN.
410/10/2020IN1
410/10/2020ED1
411/3/2020ED.
412/29/2020IN.

 

Thanks!

PeterClemmensen
Tourmaline | Level 20

Try this

 

proc sql;
   create table want as
   select *
        , (count (distinct place) > 1) as newvar
   from test
   group by ID, date
   ;
quit;