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

Hi,

suppose I have the following file:

datecompanynamecategory1category2category3category4
2010ABCa1000
2010ABCb0100
2010ABCc0010
2009ABCa1000
2009ABCb0100
2009ABCc0010
2010DEFd0010
2010DEFe0001
2010DEFf1000
2009DEFd0010
2009DEFe0001
2009DEFf1000

For each company in each year, I have several names and the corresponding category of each name.

Now out of this table I would like to create the following table:

datecompanytotal1total2total3total4
2010ABC1110
2009ABC1110
2010DEF1011
2009DEF1011

Here for each company in each year I would like to have the TOTAL sum of the categories corresponding to that particular year and company. So for example, in the first table company ABC in date 2010 had a total of 1 name of category1, 1 name of category2, 1 name of category3 and 0 names of category4, and so this is reflected in the first row of the second table.

And so on for the other years and companies like this I can make a regression on the new table.

Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions
stat_sas
Ammonite | Level 13

proc sql;

create table want as

select date,company,

sum(category1) as total1,

sum(category2) as total2,

sum(category3) as total3,

sum(category4) as total4

from have group by date,company;

quit;

View solution in original post

2 REPLIES 2
stat_sas
Ammonite | Level 13

proc sql;

create table want as

select date,company,

sum(category1) as total1,

sum(category2) as total2,

sum(category3) as total3,

sum(category4) as total4

from have group by date,company;

quit;

ilikesas
Barite | Level 11

Hi stat@sas

thanks for the solution!!!

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 1070 views
  • 0 likes
  • 2 in conversation