BookmarkSubscribeRSS Feed
PETE
Calcite | Level 5

Good afternoon – in the below data set that I have narrowed down, I’m running into the problem of how to sum up 1 column, while keeping the others constant. For example, I want to sum up the # of people that are eligible for MASS, BOSTON, SEAFOOD,

 

Dataset example is:

 

STATE

CITY

FOOD

NAME

Eligible2

MASS

BOSTON

SEAFOOD

MARY

1

MASS

BOSTON

SEAFOOD

FRANK

1

MASS

BOSTON

SEAFOOD

DAN

1

MASS

BOSTON

SEAFOOD

SAM

0

 

While what I’m hoping for an output would be:

 

STATE

CITY

FOOD

Eligible

MASS

BOSTON

SEAFOOD

3

 

 

Any suggestions?

 

Thank you!

5 REPLIES 5
dsbihill
Obsidian | Level 7
Proc SQL;
    create table want as
         select State, city, food, sum(eligible2) as eligible
            from havetable
     group by state, city, food
;
quit;

Something like this?

PETE
Calcite | Level 5

Thank you dsbihill. That got me down to just one error:

 

22

ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string,

a numeric constant, a datetime constant, a missing value, BTRIM, INPUT, PUT,

SUBSTRING, USER.

 

dsbihill
Obsidian | Level 7
Can you post your code or the part of the log above the error? You probably have an extra comma somewhere.
Loko
Barite | Level 11

Hello,

 

As an alternative you can try:

 

proc means data=sashelp.cars nway sum nonobs;
class make type origin;
var invoice;
run;

AskoLötjönen
Quartz | Level 8

Also Proc Summary can be used for purpose like this.

 

proc summary data=have sum nway ;
  class State City Food;
  var Eligible2 ;
  output out=want(drop=_type_ _freq_) sum=Eligible;
run;

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