DATA Step, Macro, Functions and more

Proc Summary (Counts and Sums)

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 15
Accepted Solution

Proc Summary (Counts and Sums)

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
SAS Employee
Posts: 15

Re: Proc Summary (Counts and Sums)

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;

View solution in original post


All Replies
Solution
‎11-03-2016 09:39 AM
SAS Employee
Posts: 15

Re: Proc Summary (Counts and Sums)

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;

Trusted Advisor
Posts: 1,554

Re: Proc Summary (Counts and Sums)

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 ?)

Super User
Posts: 11,343

Re: Proc Summary (Counts and Sums)

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.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 1124 views
  • 1 like
  • 4 in conversation