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

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

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

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

https://documentation.sas.com/?cdcId=pgmsascdc&cdcVersion=9.4_3.4&docsetId=procstat&docsetTarget=pro...

--
Paige Miller

View solution in original post

12 REPLIES 12
PeterClemmensen
Tourmaline | Level 20

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

Reeza
Super User
/*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
Obsidian | Level 7
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.
Kurt_Bremser
Super User

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

PaigeMiller
Diamond | Level 26

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

--
Paige Miller
heatherjae15
Obsidian | Level 7
This creates a diagonal. I just want the variables siteID sitename with
the number of pts enrolled
PaigeMiller
Diamond | Level 26

You need the LIST option, as I showed in my code.

--
Paige Miller
heatherjae15
Obsidian | Level 7
Ohhh, thank you
heatherjae15
Obsidian | Level 7
Paige, I am getting an error that says it can't find my data. Any thoughts?
PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
heatherjae15
Obsidian | Level 7
I fixed that now how do I remove the percent, cum frequency and cum percent?
PaigeMiller
Diamond | Level 26

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

https://documentation.sas.com/?cdcId=pgmsascdc&cdcVersion=9.4_3.4&docsetId=procstat&docsetTarget=pro...

--
Paige Miller

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 12 replies
  • 1204 views
  • 2 likes
  • 5 in conversation