DATA Step, Macro, Functions and more

Adding counts to proc report

Reply
Contributor
Posts: 55

Adding counts to proc report

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

OBSCounselorChild IDReferral StatusReferral SourceAssessment DateProgramNeighborhoods
1John2490ActiveOther9-Jun-161Central Harlem
2 2500ActiveSchool Staff/Nurse6-Jun-161East Harlem
3 2503ActiveWalk-In Center7-Jun-161East Harlem
4 2504ActiveWalk-In Center7-Jun-161East Harlem
5 2505ActiveWalk-In Center7-Jun-161East Harlem
6 2508ActiveOther13-Jun-161Central Bronx
7 2514ActiveOther9-Jun-161Central Harlem
8 2517ActiveWalk-In Center14-Jun-161East Harlem
9 2518ActiveWalk-In Center21-Jun-161East Harlem
10 2519ActiveWalk-In Center29-Jun-161Bronx Park and Fordham
 Count10     
11Jane2501ActiveInpatient2-Jun-161East Harlem
12 2502ActiveInpatient1-Jun-161East Harlem
 Count2     
 Total Count12     
 
Thanks!
 
 
 
 
 
Contributor
Posts: 25

Re: Adding counts to proc report

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;
SAS Super FREQ
Posts: 8,862

Re: Adding counts to proc report

And here's a way to do it without using a LINE statement.

cynthia

 

break_count_proc_report.png

Contributor
Posts: 55

Re: Adding counts to proc report

Posted in reply to Cynthia_sas

Thanks Cynthia, can you confirm: n=cnt____ insert variable name?

SAS Super FREQ
Posts: 8,862

Re: Adding counts to proc report

[ Edited ]

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

Contributor
Posts: 55

Re: Adding counts to proc report

Posted in reply to Cynthia_sas

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

Counselor n Child ID Referral Status Referral Source Assessment Date Program Neighborhoods
Mabel12531ActiveSpecialty Clinic07JUL20161East Harlem
 12532ActiveSpecialty Clinic06JUL20161Hunts Point and Mott Haven
 12537ActiveInpatient13JUL20161East Harlem
Mabel37600 3524JUL2129346
Martha12485ActiveOther01JUL20161Bronx Park and Fordham
Martha12485 Other01JUL20161Bronx Park and Fordham
SAS Super FREQ
Posts: 8,862

Re: Adding counts to proc report

Hi:
Notice how, in my PROC REPORT code, I have a usage of "DISPLAY" for the numeric variables HEIGHT and WEIGHT? If I did NOT have DISPLAY for them, I would have gotten an automatic summary on the break line. You have to change the usage of your numeric variables to DISPLAY (such as for the DATE variable) and to suppress the repeat of group or order variables on the break line, you want to add the SUPPRESS option to your BREAK statement.. In your original code, you do not have any usages or BREAK statement, so it is not clear to me what program you used to take your most recent screen shot.

cynthia
Ask a Question
Discussion stats
  • 6 replies
  • 395 views
  • 0 likes
  • 3 in conversation