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