BookmarkSubscribeRSS Feed
michokwu
Quartz | Level 8

Hello,

I'm creating a summary table and want to calculate the weighted counts and sums by group and subgroup. I have this summary by subgroups in different files but I want it as 1 summary table, it goes through 2001 to 2017. When I tried to that, I did not get the desired result.

 (See excel sheet attached) and my code below

proc tabulate data=analysis1.in out=analysis1.in_w(drop=_type_);
var weight;
class Year race_sex education;
table Year*race_sex*education
		weight*(n sum);
run;

 

Regards,

3 REPLIES 3
michokwu
Quartz | Level 8

Please see Sheet2 attached. Thank you

ballardw
Super User

@michokwu wrote:

Hello,

I'm creating a summary table and want to calculate the weighted counts and sums by group and subgroup. I have this summary by subgroups in different files but I want it as 1 summary table, it goes through 2001 to 2017. When I tried to that, I did not get the desired result.

 (See excel sheet attached) and my code below

proc tabulate data=analysis1.in out=analysis1.in_w(drop=_type_);
var weight;
class Year race_sex education;
table Year*race_sex*education
		weight*(n sum);
run;

 

Regards,


You really need to provide an example of the data and what you expect the results for that example data to actually be. We need an actual data set to test code against. Your existing code does not show any attempt to calculate a "weighted count" and I am not sure that  you are using the term appropriately.

 

If you are not getting the desired result you need to show what the actual desired (or expected) result should be. Other wise have to guess, and with out actual data we can't even guess reasonably.

 

The way you present your "what I want" does not make a lot of sense with the "count" and "sum" in multiple places. I am moderately sure that Proc tabulate will not line up the columns as shown.

 

Since your have separate tows in our desired output for race_sex and education you do not want to use race_sex*education as the * used that way nests education within race.

Do you want the "person weight total

You can get a bit closer with :

proc tabulate data=analysis1.in out=analysis1.in_w(drop=_type_);
   var weight;
   class Year race_sex education;
   table year  weight*(n sum);
   table Year*race_sex
   		weight*(n sum);
   table Year*education
   		weight*(n sum);
run;

But that will not make the columns line up in Excel the way you show. That would be possible with the Report Writing Interface in a data step with appropriate data structure but not with Tabulate.

 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 974 views
  • 0 likes
  • 3 in conversation