Hi everyone,
I use proc report to get a listing of all new enrollees we get in a certain time period. I'd like to add a row(s) to tally a count of new enrollees using the childid variable. Here is my code:
proc report data=assessedkids3 nowd headline;
title1 "&month Enrollment Report";
columns OBS counselor childid CaseDispositionDesc eligibilitycriteriaid AssessmentDate_HW ProgramTypeID Neighborhoods ;
define CaseDispositionDesc /'Referral Status';
define counselor /'Counselor' group format=$counselor.;
define childid / 'Child ID';
define AssessmentDate_HW / 'Assessment Date';
define eligibilitycriteriaid / 'Referral Source';
define ProgramTypeID / 'Program';
where &start_date <= dateeval <= &end_date;
define obs / computed ;
define Neighborhoods / 'Neighborhoods';
compute obs ;
count+1 ;
obs=count ;
endcomp ;
run;
and here is my output with. The bold rows are what I would like added What I would like to see. Any advice as to how to get this would be appreciated!
SAS Output
OBS | Counselor | Child ID | Referral Status | Referral Source | Assessment Date | Program | Neighborhoods |
1 | John | 2490 | Active | Other | 9-Jun-16 | 1 | Central Harlem |
2 | 2500 | Active | School Staff/Nurse | 6-Jun-16 | 1 | East Harlem | |
3 | 2503 | Active | Walk-In Center | 7-Jun-16 | 1 | East Harlem | |
4 | 2504 | Active | Walk-In Center | 7-Jun-16 | 1 | East Harlem | |
5 | 2505 | Active | Walk-In Center | 7-Jun-16 | 1 | East Harlem | |
6 | 2508 | Active | Other | 13-Jun-16 | 1 | Central Bronx | |
7 | 2514 | Active | Other | 9-Jun-16 | 1 | Central Harlem | |
8 | 2517 | Active | Walk-In Center | 14-Jun-16 | 1 | East Harlem | |
9 | 2518 | Active | Walk-In Center | 21-Jun-16 | 1 | East Harlem | |
10 | 2519 | Active | Walk-In Center | 29-Jun-16 | 1 | Bronx Park and Fordham | |
Count | 10 | ||||||
11 | Jane | 2501 | Active | Inpatient | 2-Jun-16 | 1 | East Harlem |
12 | 2502 | Active | Inpatient | 1-Jun-16 | 1 | East Harlem | |
Count | 2 | ||||||
Total Count | 12 |
The N statistic on a numeric variable like date should give you what you need. Try something like this:
title1 "&month Enrollment Report"; proc report data=assessedkids3 nowd headline; where &start_date <= dateeval <= &end_date; columns dateeval counselor childid CaseDispositionDesc eligibilitycriteriaid AssessmentDate_HW ProgramTypeID Neighborhoods ; define CaseDispositionDesc /'Referral Status'; define counselor /'Counselor' group format=$counselor.; define childid / 'Child ID'; define AssessmentDate_HW / 'Assessment Date'; define eligibilitycriteriaid / 'Referral Source'; define ProgramTypeID / 'Program'; define dateeval / n noprint; define Neighborhoods / 'Neighborhoods'; compute after counselor;
count = dateeval.N;
line count;
endcomp; run;
And here's a way to do it without using a LINE statement.
cynthia
Thanks Cynthia, can you confirm: n=cnt____ insert variable name?
I don't know what you are asking me to confirm. I created an alias for N (calling the alias CNTAGE) so I could refer to the simple name CNTAGE in my COMPUTE block. In this example, it didn't make a lot of difference, I could have used just N; however, in several of my other, more advanced reports, I get the count of more than 1 column on the report, so I might use N for different variables, such as N=CNTAGE and N=CNTStatus so that, depending on the BREAK variable(s), I might have different subtotals at different points on the report. And, using an alias this way gives me a method, using the alias reference to keep straight what I am going to display and where.
And, it is not necessarily the variable name -- I could have said N=wombat or N=koala or N=mycount. I pick N=cntage, because that is the name that makes it clear to me, years later, what I intended that alias to do.
cynthia
Ah makes sense. for some reason my output summarizes all of the columns. is there a way to specifiy a specific column to summarize?
SAS Output
Mabel | 1 | 2531 | Active | Specialty Clinic | 07JUL2016 | 1 | East Harlem |
1 | 2532 | Active | Specialty Clinic | 06JUL2016 | 1 | Hunts Point and Mott Haven | |
1 | 2537 | Active | Inpatient | 13JUL2016 | 1 | East Harlem | |
Mabel | 3 | 7600 | 35 | 24JUL2129 | 3 | 46 | |
Martha | 1 | 2485 | Active | Other | 01JUL2016 | 1 | Bronx Park and Fordham |
Martha | 1 | 2485 | Other | 01JUL2016 | 1 | Bronx Park and Fordham |
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.