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

Hello, I need to transform this data

 

sinistrepolicedate survenanaceprime 1prime 2
S1p101/01/201510050
S2p101/01/2015080
S3p120/06/20188020

to this one, 

 

police date survenanaceprime 1prime 2
p101/01/2015100130
p120/06/20188020

 

 

In fact, for each "police", i have to sum the claims amount (prime 1 prime 2) of the claims (S1 and S2) which happen in the same date (date survenance), 

Thank you !

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

This is a perfect example of where to use PROC SUMMARY.

 

proc summary nway data=have;
    class police date;
    var prime1 prime2;
    output out=want sum=;
run;
--
Paige Miller

View solution in original post

7 REPLIES 7
PaigeMiller
Diamond | Level 26

This is a perfect example of where to use PROC SUMMARY.

 

proc summary nway data=have;
    class police date;
    var prime1 prime2;
    output out=want sum=;
run;
--
Paige Miller
Mirou
Fluorite | Level 6

thank you !

PeterClemmensen
Tourmaline | Level 20

An alternative PROC SQL Approach. I like @PaigeMillers code better though 🙂

 

data have;
input sinistre $ police $ datesurvenanace:ddmmyy10. prime1 prime2;
format datesurvenanace ddmmyy10.;
datalines;
S1 p1 01/01/2015 100 50
S2 p1 01/01/2015 0 80
S3 p1 20/06/2018 80 20
;

proc sql;
   create table want as
   select police,
          datesurvenanace,
          sum(prime1) as prime1,
          sum(prime2) as prime2
   from have
   group by police, datesurvenanace;
quit;
PaigeMiller
Diamond | Level 26

@PeterClemmensen wrote:

An alternative PROC SQL Approach. I like @PaigeMillers code better though 🙂


Thanks. In my opinion, PROC SUMMARY/PROC MEANS is a fundamental tool that every SAS user ought to be familiar with. An advantage over PROC SQL here is that if you take the option NWAY out of my example code, you get a lot more results from PROC SUMMARY easily (and which are meaningful in many situations), which would take a lot more effort to get from SQL.

--
Paige Miller
PeterClemmensen
Tourmaline | Level 20

@PaigeMiller Couldn't agree more. I have a habit of going with PROC MEANS. Though the Summary Procedure seems to handle situations like this smoother.

data_null__
Jade | Level 19

@PeterClemmensen wrote:

@PaigeMiller Couldn't agree more. I have a habit of going with PROC MEANS. Though the Summary Procedure seems to handle situations like this smoother.


MEANS and SUMMARY are the same procedure they just have different defaults, like printed output.

 

PROC SUMMARY is my favorite procedure. Robot Happy 

ballardw
Super User

@PaigeMiller wrote:

@PeterClemmensen wrote:

An alternative PROC SQL Approach. I like @PaigeMillers code better though 🙂


Thanks. In my opinion, PROC SUMMARY/PROC MEANS is a fundamental tool that every SAS user ought to be familiar with. An advantage over PROC SQL here is that if you take the option NWAY out of my example code, you get a lot more results from PROC SUMMARY easily (and which are meaningful in many situations), which would take a lot more effort to get from SQL.


Yes!

 

One of my projects actually involves enough class variables and levels of those variables that the summary data is larger than the original but that one pass allows me to select combinations of the summarized variables for different audiences resulting in over a couple hundred different report documents customized for each audience without much fuss.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 1412 views
  • 8 likes
  • 5 in conversation