turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- Base SAS Programming
- /
- Proc Summary (Counts and Sums)

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

10-28-2016 12:56 PM

Need some help with proc summary.

My data is attached with how it currently looks and what I'm hoping it to look like.

Here's the code I have;

rsubmit;

proc summary data=worked2 nway;

var talk_secs acw_secs total_secs total_mins;

class yr mth dt rep supervisor tactic;

output out = daily_counts(drop=_type_ rename=(_freq_=tl_count) sum=talk_secs acw_secs total_secs total_mins);

run;

proc sort data=daily_counts out=daily_counts;

by dt;

proc print data=daily_counts (obs=10);

run;endrsubmit;

Accepted Solutions

Solution

11-03-2016
09:39 AM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

10-28-2016 03:33 PM

If you're not restricted to using PROC SUMMARY, you may find the count() and sum() functions in PROC SQL easier to work with when aggregating data longitudinally. The code below will create the data set you're looking for.

Disclaimer: creating a new line using the sum() and count() function isn't necessary, but was just done for illustrative purposes.

proc sql;

create table work.daily_counts as

select distinct rep, supervisor, year, month, date, tactic

, count(account_id) as id_count

, sum(talk_secs) as sum_talk_secs

, sum(acw_secs) as sum_acw_secs

, sum(total_secs) as sum_total_secs

, sum(total_mins) as sum_total_mins

from work.worked2

group by date, tactic

order by date;

quit;

proc print data=work.daily_counts(obs=10);

run;

All Replies

Solution

11-03-2016
09:39 AM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

10-28-2016 03:33 PM

If you're not restricted to using PROC SUMMARY, you may find the count() and sum() functions in PROC SQL easier to work with when aggregating data longitudinally. The code below will create the data set you're looking for.

Disclaimer: creating a new line using the sum() and count() function isn't necessary, but was just done for illustrative purposes.

proc sql;

create table work.daily_counts as

select distinct rep, supervisor, year, month, date, tactic

, count(account_id) as id_count

, sum(talk_secs) as sum_talk_secs

, sum(acw_secs) as sum_acw_secs

, sum(total_secs) as sum_total_secs

, sum(total_mins) as sum_total_mins

from work.worked2

group by date, tactic

order by date;

quit;

proc print data=work.daily_counts(obs=10);

run;

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

10-28-2016 03:36 PM

I see no problem with your code. Run it and you should get what you are looking for.

The "MyData" - is it your input or your result of the code?

It seems to me that you are looking at your input dataset, and not at your PROC PRINT result;

If I'm wrong, please post your full log.

What SAS installation (platform) are you using ?

(Why using rsubmit - endrsubmit ?)

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

10-28-2016 08:21 PM

Many users here don't want to download Excel files because of virus potential, others have such things blocked by security software. Also if you give us Excel we have to create a SAS data set and due to the non-existent constraints on Excel data cells the result we end up with may not have variables of the same type (numeric or character) and even values.

You can use instruction here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... to transform your current SAS data set into data step code to post in the forum or attach as a text file.