Count Behaviors-Repeated Measures

Reply
Regular Contributor
Posts: 150

Count Behaviors-Repeated Measures

I have repeated measures data (long format) and my outcome variable is binary 1=yes, 0=no. I am looking at factors associated with the outcome over time. What I want is how many participants reported the outcome at each visit, so some participants could have reported it at 1 visit, some at 2, 3, 4 visits, etc...I am not sure how to have SAS tell me this. Any advice is appreciated.

Frequent Contributor
Posts: 144

Re: Count Behaviors-Repeated Measures

Posted in reply to rfarmenta

You can use sql to know this

proc sql;

select distinct(visits), sum(binary_variable=1)  as result

from dataset

group by visit

quit;

Regular Contributor
Posts: 150

Re: Count Behaviors-Repeated Measures

Posted in reply to arodriguez

Maybe I am running the code incorrectly but that code actually just gives me the same result as running a proc freq with a cross tab for visit and the outcome. So it esentially just tells me who reported the behavior and each visit. My original question maybe doesn't make sense but I want to try to figure out who reported the behavior at only 1 visit, who reported it at 2 visits, and who reported it at all visits...Does that make sense? Thank you for your help.

Here is the code I used:

proc sql;

select distinct(visitnum),sum(pfsy6mo=1) as pfsycount

from merged_visits2

group by visitnum;

quit;

Frequent Contributor
Posts: 144

Re: Count Behaviors-Repeated Measures

Posted in reply to rfarmenta

Sorry then, I misunderstood your question.

The easiest that comes to my mind is first of all, sort data

proc sort data=merged_visit2;

by patid visitnum pfsy6mo;

run;

and create a variable with retain that count how many time this person has answered

data aux_data;

set merged_visit2

by patid visitnum pfsy6mo;

retain num_answers;

if first.patid then num_answers=0;

if pfs6ymo=1 then num_answers=num_answers+1;

if last.patid;

run;

doing this, you will get a only record by patid with the number of questions answered. Then with a proc freq or with sql you can get the number of patients that answers question.

To know who reported I guess that you can transpose this dataset using as column the visits and transposing the pfsy6mo

proc transpose data=merged_visit2 out=trans_data;

by patid;

id visitnum;

var pfsy6mo;

quit;

Ask a Question
Discussion stats
  • 3 replies
  • 219 views
  • 1 like
  • 2 in conversation