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.
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;
The sums you posted are not your actual wanted sums, right?
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;
Thanks!
It worked!
@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.
Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.
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.
Ready to level-up your skills? Choose your own adventure.