BookmarkSubscribeRSS Feed
rfarmenta
Obsidian | Level 7

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.

3 REPLIES 3
arodriguez
Lapis Lazuli | Level 10

You can use sql to know this

proc sql;

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

from dataset

group by visit

quit;

rfarmenta
Obsidian | Level 7

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;

arodriguez
Lapis Lazuli | Level 10

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;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 631 views
  • 1 like
  • 2 in conversation