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

Hello!

 

I have a dataset (simplified example) containing the following variables;

 

Data salary;

input age_group$ gender$ year$ salary;

25-29 M 2017 25000

25-29 M 2018 30000

25-29 W 2017 30000

25-29 W 2018 35000

30-34 M 2017 25000

30-34 M 2018 50000

30-34 W 2017 25000

30-34 W 2018 75000

 

 

I would like to create a table looking like this:

 

25-29 (age_group)

30-34 (age_group)

 

Gender

Gender

 

M

W

 

M

W

 

 

Salary

Salary

 

Salary

Salary

 

 

Sum

Sum

 

Sum

Sum

 

2018

64000

35000

 

50000

75000

 

2017

34000

30000

 

25000

25000

 

 

M and W should be under agegroup and gender, not separeted ( there was an error in the HTML when I made this post).

 

Same table but from notepad;

 

  25-29 (age_group) 30-34 (age_group)
  Gender Gender
  M W   M W 
  Salary Salary   Salary Salary 
  Sum Sum   Sum Sum 
2018 64000 35000   50000 75000 
2017 34000 30000   25000 25000 

 

 

 

 I have tried proc tabulate and proc transpose, but probably I am doing somethin wrong as I don't get the result I want.  Would be super if someone could provide a code for this.

 

1 ACCEPTED SOLUTION

Accepted Solutions
ed_sas_member
Meteorite | Level 14

Hi @Chris_Loke 

 

You can try this:

 

proc tabulate data=salary;
	var salary;
	class age_group gender year;
	table year, (age_group*gender) * (salary*sum);
run;

View solution in original post

4 REPLIES 4
PeterClemmensen
Tourmaline | Level 20

The sums you posted are not your actual wanted sums, right?

ed_sas_member
Meteorite | Level 14

Hi @Chris_Loke 

 

You can try this:

 

proc tabulate data=salary;
	var salary;
	class age_group gender year;
	table year, (age_group*gender) * (salary*sum);
run;
Chris_Loke
Fluorite | Level 6

Thanks!

 

It worked!

ballardw
Super User

@Chris_Loke wrote:

Hello!

 

 

M and W should be under agegroup and gender, not separeted ( there was an error in the HTML when I made this post).

 

Perhaps use a plain text editor, the SAS editor will work, to outline the positions instead of HTML. Paste into a code box opened on the forum using the {I} icon. There is more than one way to interpret your above requirement and some of the interpretations could be kind of wonky.

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