Unique outcomes across visits

Accepted Solution Solved
Reply
Regular Contributor
Posts: 150
Accepted Solution

Unique outcomes across visits

I have data from 5 study visits that assessed health behaviors. The same questions were asked at each visit and I would like to determine how many unique participants reported one behavior. I have the data sets appended in long format, so I can run a proc freq and get that 110 participants reported the behavior across all visits but I want to know how many of those are unique participants versus the same participants reporting the behavior at each visit. Ideally I would like to know how many participants reported the behaviors at all visits, how many at any visit, and how many reported 1, 2, 3, and 4 visits. I previously asked a similar question but was not able to figure this out. Any suggestions would be greatly appreciated.


Accepted Solutions
Solution
‎03-20-2015 07:48 PM
Respected Advisor
Posts: 3,887

Re: Unique outcomes across visits

A SQL approach:

proc sql;

/*  create table want as*/

  select pid, behavior, count(behavior) as count

  from have

/*  where behavior='1'*/

  group by pid,behavior

  ;

quit;

View solution in original post


All Replies
Super User
Posts: 10,483

Re: Unique outcomes across visits

If by long you mean you have data as:

ID VisitDate Behavior or similar:

Then

Data temp;

     set have;

     behaviorcount = (behavior='behavior value of interest');

run;

proc summary data=temp nway;

class ID;

var behaviorcount;

output out=want sum=;

run;

will have the number of visits with the specified behavior across all visits for each ID. ID could be several variables that uniquely identify the patient.

Super User
Posts: 17,784

Re: Unique outcomes across visits

You can also use either count distinct in a proc sql or use a double proc freq - first time include the participant ID, the second you don't. 

For more help please post sample data and expected output that corresponds to your sample data.

Regular Contributor
Posts: 150

Re: Unique outcomes across visits

I am not sure I understand the code from ballardw and I tried count distinct but that doesn't seem to give me what I want either. I can't attach an excel right now for some reason but below is a short example of what I would want to do. I just made up the example data. I would want to know how many people did the behavior at 1 visit, at 2 visits, at 3 visits, etc. so from the data the results would be this, 1=yes, 2= no in the code for behavior:

behaviorcount

0=1 (did not report)

1=1

2=3

3=1

4=0

5=1

pidbehaviorvisit
101
112
113
104
105
201
202
203
204
311
312
313
411
402
403
404
405
511
512
513
514
515
601
612
613
604
605
711
712
Super User
Posts: 10,483

Re: Unique outcomes across visits

With that coding:

proc means data=have sum;

class pid;

var behavior;

run;

If 1 represents have the behavior then the sum would be how many visits exhibited the behavior for each PID value.

Solution
‎03-20-2015 07:48 PM
Respected Advisor
Posts: 3,887

Re: Unique outcomes across visits

A SQL approach:

proc sql;

/*  create table want as*/

  select pid, behavior, count(behavior) as count

  from have

/*  where behavior='1'*/

  group by pid,behavior

  ;

quit;

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 202 views
  • 0 likes
  • 4 in conversation