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.
You can use sql to know this
proc sql;
select distinct(visits), sum(binary_variable=1) as result
from dataset
group by visit
quit;
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;
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;
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.