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

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;

1 ACCEPTED SOLUTION

Accepted Solutions
jhlaramore
SAS Employee

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

3 REPLIES 3
jhlaramore
SAS Employee

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;

Shmuel
Garnet | Level 18

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

ballardw
Super User

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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 30377 views
  • 2 likes
  • 4 in conversation