BookmarkSubscribeRSS Feed
Vigneswar
Obsidian | Level 7

Hi,

 

I need to group a column based on the other common column in SAS DI.

 

I have below dataset as the input.

 

INPUT DATA:

 

Product                date                       customer             sales org              actual

10                             01/10/2015         124                         IT10                        110

10                             01/10/2015         124                         IT11                        213

 

I want the below output,

 

OUTPUT:

Product                date                       customer             sales org

10                            01/10/2015         124                         IT10                        323

 

Can anyone give suggestion on this?

 

 

Thanks in advance!!!

 

Vigneswar

4 REPLIES 4
Vigneswar
Obsidian | Level 7

Hi,

 

I need to group a column based on the other common column in SAS DI.

 

I have below dataset as the input.

 

INPUT DATA:

 

Product                date                       customer             sales org              actual

10                             01/10/2015         124                         IT10                        110

10                             01/10/2015         124                         IT11                        213

 

I want the below output,

 

OUTPUT:

Product                date                       customer             sales org

10                            01/10/2015         124                         IT10                        323

 

Can anyone give suggestion on this?

 

 

Thanks in advance!!!

 

Vigneswar

Shmuel
Garnet | Level 18

Assuming data is already sorted by: product date customer and sales org:

 

data wany;

  set have;

    by product date customer;

         retain first_org total;

         if first.customer then do;

            first_org = sales_org;

            total = actual;

         end;

        else total = sum(of total, actual);

        if last.customer then do;

          sales_org = first_org;

          actual = total;

          output;

      end;

run;

Kurt_Bremser
Super User

A slightly different data step solution would be this:

data have;
input product date :ddmmyy10. customer sales_org $ actual;
format date ddmmyy10.;
cards;
10 01/10/2015 124 IT10 110
10 01/10/2015 124 IT11 213
;
run;

data want;
set have (rename=(sales_org=_sales_org actual=_actual));
by product date customer;
retain sales_org;
if first.customer then sales_org = _sales_org;
actual + _actual;
if last.customer then output;
drop _sales_org _actual;
run;

Note that the basic logic is the same as @Shmuel's

slchen
Lapis Lazuli | Level 10


proc sql;
select distinct product,date,customer,min(sales_org) as sales_org, sum(actual) as actual from have group by product;
quit;

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!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 4 replies
  • 800 views
  • 0 likes
  • 4 in conversation