🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Fluorite | Level 6

## 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

1 ACCEPTED SOLUTION

Accepted Solutions
Opal | Level 21

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

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
5 REPLIES 5
PROC Star

## 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'

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
Fluorite | Level 6

## 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.
PROC Star

## 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.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
Opal | Level 21

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

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
Fluorite | Level 6

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

Thank you for your suggestion. I will try that.
Discussion stats
• 5 replies
• 3365 views
• 0 likes
• 3 in conversation