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

Hello!

I am trying to count multiple committees served over 3 years on one row.

Currently my Proc Report is repeating the committee on to separate rows by year thus the count is also on the same row. 

 

Current Code:

proc report data=committee_sort;
column division sort dname Name CommitteeName year(count),sum;
define division/group order=data;
define sort/noprint order=data;
define dname/group;
define Name/group;
define CommitteeName/group;
define year/across;
define count/analysis;
rbreak after/summarize;
run;

 

Sample Data:

Here is one row right now..

When a person serves on the same committee 2 years in a row it shows as below.

DivisiondnameNameCommitteeName201420152016
HAMStudent 3 Advisory Committee1..
    ..1

 

 

Here is how I would like to have it display and count.

I want one row when a committee is served on for 2 or 3 years and then provide a count across years column.

DivisiondnameNameCommitteeName201420152016Total Across Years
HAMStudent 3Advisory Committee1.12

 

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Data in the form of a dataset please.  As such this is untested:

proc transpose data=have out=want prefix=year;
  by comitee_name;
  var count;
  id year;
  idlabel year;
run;

data want;
  set want;
  total=sum(of year:);
run;

Step 1 transposes the data so years go across, then the datastep simply sums across the row.

View solution in original post

3 REPLIES 3
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Proc report is not the place to be doing data manipulation.  Do that in a datastep.  Next up post test data in the form of a datastep, just showing some text tells us very little.  Does the second row in your data not have the id variables?  If so how do you know both those rows belong to the same ids?

agambacc
Calcite | Level 5

My apologies. It may be the case that proc report is not the place for this however I was unsure of how to handle it in the report or datastep. What I posted was the output which is not in the format that I prefer. 

data test_r (keep=id year department division committeename name count);
set test;
count=1;
run;

IDyearDepartmentDivisionCommitteeNameNameCount
12014MBSSUniversity Budget CommitteePerson 11
12015MBSSUniversity Budget CommitteePerson 11
22015MBSSAd Hoc Committee on Faculty Standards of ConductPerson 21
22016MBSSAd Hoc Committee on Faculty Standards of ConductPerson 21
32014MBSSAd Hoc University Committee on EntrepreneurshipPerson 31
32015MBSSCooperative Research CommitteePerson 31
32016MBSSRadiation Safety CommitteePerson 31
42014MBSSScholar Awards CommitteePerson 41
42015MBSSScholar Awards CommitteePerson 41
42016MBSSScholar Awards CommitteePerson 41
62014MBSSExecutive CommitteePerson 51
62016MBSSBiological Sciences Advisory CommitteePerson 51
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Data in the form of a dataset please.  As such this is untested:

proc transpose data=have out=want prefix=year;
  by comitee_name;
  var count;
  id year;
  idlabel year;
run;

data want;
  set want;
  total=sum(of year:);
run;

Step 1 transposes the data so years go across, then the datastep simply sums across the row.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 1294 views
  • 0 likes
  • 2 in conversation