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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 3 replies
  • 238 views
  • 2 likes
  • 3 in conversation