BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
rfarmenta
Obsidian | Level 7

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

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

5 REPLIES 5
ballardw
Super User

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.

Reeza
Super User

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.

rfarmenta
Obsidian | Level 7

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
ballardw
Super User

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.

Patrick
Opal | Level 21

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;

sas-innovate-2024.png

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.

 

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
  • 5 replies
  • 523 views
  • 0 likes
  • 4 in conversation