DATA Step, Macro, Functions and more

Counting the number of patients and frequencies for other categorical variables per study arm

Accepted Solution Solved
Reply
Contributor
Posts: 43
Accepted Solution

Counting the number of patients and frequencies for other categorical variables per study arm

Hello,

 

I have a clinical trial dataset and am trying to determine the frequencies of a few categorical variables as well as the number of unique patients per study arm at baseline.

 

I had initially done proc freq, but since I have multiple rows for each patient due to multiple visits per patient I was told that for proc freq there should only be one row/person.  So, the values I got were a count of the same patient numerous times.  I was told that I could use the where statement to only get the frequency at the baseline visit, but that did not work either.  No observations were read.

 

My code is below:

proc freq data=xxxxl;
where visit="001";
tables race*group sex*group /norow nopercent;
run;

 

I received the following message in the log: NOTE: No observations were selected from data set xxx.
NOTE: There were 0 observations read from the data set xxx.
WHERE visit='001'

 

I am not sure what I did wrong and what I need to do to get the correct answer.  

I am expecting the output to look as follows:

Group 1    Group 2

xxx               xxx   (these numbers would the number of unique patients in each group)

Race    Group 1    Group 2

White    xxx            xxx

Black     xxx            xxx

Other     xxx            xxx

 

Any help would be greatly appreciated.

 

Thanks


Accepted Solutions
Solution
‎12-09-2016 04:22 PM
Respected Advisor
Posts: 4,646

Re: Counting the number of patients and frequencies for other categorical variables per study arm

[ Edited ]

Assuming your data is sorted by some patient_Id variable, try keeping the first record for each patient:

 

data patients;
set xxxxl;
by patient_Id;
if first.patient_Id;
run;

 

proc freq data=patients;
tables race*group sex*group /norow nopercent;
run;

PG

View solution in original post


All Replies
Valued Guide
Posts: 797

Re: Counting the number of patients and frequencies for other categorical variables per study arm

Visit is a character variable?

 

Then do a proc freq of visit to see what values it actually has in the data step.

 

And also note;

 

where visit='001' will NOT match a right-justified 4-byte visit value of ' 001' (note leading space).  If that's the problem, then either

   where visit=' 001'

or

   where left(visit)='001'

 

 

Contributor
Posts: 43

Re: Counting the number of patients and frequencies for other categorical variables per study arm

Yes, visit is a character variable. I strip(visit)="001.00" and I got a result but it did not seem to subset the data to give the counts with only one observation per patient. The number I got was much more than it should be. Thanks.
Valued Guide
Posts: 797

Re: Counting the number of patients and frequencies for other categorical variables per study arm

If you get fewer "001.00" cases than expected, then perhaps the original visit coding has errors or incosistencies.  I think you have to find a patient with no visit="001.00" to see whether there are other codes indicating baseline visit.

Solution
‎12-09-2016 04:22 PM
Respected Advisor
Posts: 4,646

Re: Counting the number of patients and frequencies for other categorical variables per study arm

[ Edited ]

Assuming your data is sorted by some patient_Id variable, try keeping the first record for each patient:

 

data patients;
set xxxxl;
by patient_Id;
if first.patient_Id;
run;

 

proc freq data=patients;
tables race*group sex*group /norow nopercent;
run;

PG
Contributor
Posts: 43

Re: Counting the number of patients and frequencies for other categorical variables per study arm

Thank you for your suggestion. I will try that.
☑ This topic is SOLVED.

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

Discussion stats
  • 5 replies
  • 204 views
  • 0 likes
  • 3 in conversation