I need help creating a variable for number enrolled. I need a table that has
siteID siteName number enrolled. How can I create a variable that will count each patient so the frequencies turn out correctly?
Thanks
@heatherjae15 wrote:
I fixed that now how do I remove the percent, cum frequency and cum percent?
proc freq data=have;
table sitename*siteid/list nocum nopercent;
run;
You might want to look at the PROC FREQ documentation to see the wide variety of options available.
@heatherjae15 Hi and welcome to the SAS Community.
Are you able to post some example of what your data looks like along with the desired result based on that data? Makes it much easier to provide a usable code answer.
/*This demonstrates how to count the number of unique occurences of a variable
across groups. It uses the SASHELP.CARS dataset which is available with any SAS installation.
The objective is to determine the number of unique car makers by origin/
Note: The SQL solution can be off if you have a large data set and these are not the only two ways to calculate distinct counts.
If you're dealing with a large data set other methods may be appropriate.*/
*Count distinct IDs;
proc sql;
create table distinct_sql as
select origin, count(distinct make) as n_make
from sashelp.cars
group by origin;
quit;
*Double PROC FREQ;
proc freq data=sashelp.cars noprint;
table origin * make / out=origin_make;
run;
proc freq data=origin_make noprint;
table origin / out= distinct_freq;
run;
title 'PROC FREQ';
proc print data=distinct_freq;
run;
title 'PROC SQL';
proc print data=distinct_sql;
run;
https://github.com/statgeek/SAS-Tutorials/blob/master/count_distinct_by_group.sas
@heatherjae15 wrote:
I need help creating a variable for number enrolled. I need a table that has
siteID siteName number enrolled. How can I create a variable that will count each patient so the frequencies turn out correctly?
Thanks
@heatherjae15 wrote:
I cant post the data. I currently have sitename and siteId. I need to make a table that shows siteID, sitename and enrolled subjects. so it is a 3 column table with the siteid sitename and number of enrolled subjects.
Don't post actual sensible data. Make up a few observations with fake data, just enough to illustrate your issue. Post as data step with datalines.
Don't force us to make guesses, help us to help you.
@heatherjae15 wrote:
I cant post the data. I currently have sitename and siteId. I need to make a table that shows siteID, sitename and enrolled subjects. so it is a 3 column table with the siteid sitename and number of enrolled subjects.
proc freq data=have;
table sitename*siteid/list;
run;
This implies that the input data has one record per patient. If that's not the case, then you need to state more about how the data is organized, and follow the advice of @Kurt_Bremser above.
You need the LIST option, as I showed in my code.
show us the LOG from your code, not just the ERROR messages, but the code as it appears in the log, plus the error messages.
Please click on the {i} icon and paste the log AS TEXT into the window that appears. Do not skip this step.
@heatherjae15 wrote:
I fixed that now how do I remove the percent, cum frequency and cum percent?
proc freq data=have;
table sitename*siteid/list nocum nopercent;
run;
You might want to look at the PROC FREQ documentation to see the wide variety of options available.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.
Ready to level-up your skills? Choose your own adventure.