BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
geneshackman
Pyrite | Level 9

Hi all. I have a data set like this

 

County Race Data
Albany White 3
Albany Black 2
Albany Asian 5
Albany Pacific Islander 3
Allegany White 1
Allegany Black 6
Allegany Asian 2
Allegany Pacific Islander 4

 

I want to add together the lines for "Asian" and "Pacific Islander" but leave the rest of the lines as they are. So, the resulting race categories would be White, Black and Asian/Pacific Islander, with the numbers for those last two combined.

 

Any simple way to do this?

 

Thanks

 

Gene

 

1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

Hi @geneshackman,

 

I would create a format and use it in a PROC SUMMARY step:

proc format;
value $race
'Asian','Pacific Islander'='Asian/Pacific Islander';
run;

proc summary data=have nway;
class county race / order=data;
format race $race.;
var data;
output out=want(drop=_:) sum=;
run;

View solution in original post

3 REPLIES 3
FreelanceReinh
Jade | Level 19

Hi @geneshackman,

 

I would create a format and use it in a PROC SUMMARY step:

proc format;
value $race
'Asian','Pacific Islander'='Asian/Pacific Islander';
run;

proc summary data=have nway;
class county race / order=data;
format race $race.;
var data;
output out=want(drop=_:) sum=;
run;
geneshackman
Pyrite | Level 9
This seems to be the way. Thanks.
ballardw
Super User

One way:

data have;
   infile datalines delimiter=',';
   input County :$15. Race :$20. Data;
datalines;
Albany,White,3
Albany,Black,2
Albany,Asian,5
Albany,Pacific Islander,3
Allegany,White,1
Allegany,Black,6
Allegany,Asian,2
Allegany,Pacific Islander,4
;

proc format;
value $comb
'Asian','Pacific Islander'='Asian/Pacific Islander';
run;
/* create a new data set*/
proc summary data=have nway;
   class county race;
   format race $comb.;
   var data;
   output out=want (drop=_:) sum=;
run;
/* some different report tables*/

proc tabulate data=have;
class county race;
format race $comb.;
var data;
table county,
race*data
;
table county*race,
data
;
table race*(county all='Race total'),
data
;
table county*(race all='County total') all='Overall total',
data
;
run;

This creates a new data set. "Adding up lines" in data set is a poor description.

A better format would include all of the values but works for your limited example.

Formats are an extremely powerful tool in SAS. Groups of many types can be created from different ranges of the same variable. I have up to a dozen Age related formats that are used in the Report, Analysis or Graphing steps.

The groups created by a format are honored by almost every procedure and can reduce coding associated with creating new variables.

 

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 3 replies
  • 470 views
  • 2 likes
  • 3 in conversation