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.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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