Hello. I have the following dataset
Group_Category | Group | Total | Female | Male | Hispanic | NotHispanic | |
Group A | GroupA_1 | 32 | 16 | 16 | 2 | 30 | |
Group A | GroupA_2 | 30 | 14 | 16 | 5 | 25 | |
Group A | GroupA_3 | 10 | 6 | 4 | 6 | 4 | |
Group B | GroupB_1 | 10 | 9 | 1 | 1 | 9 | |
Group B | GroupB_2 | 44 | 20 | 24 | 4 | 40 | |
Group B | GroupB_3 | 60 | 20 | 40 | 5 | 55 |
What I would like to do is modify the variable names for all the groups. Something like this to be outputted eventually to csv or excel and merging Group A and B for their corresponding columns _1, _2, _3.
Category_1 | Category_2 | Group A | Group B | ||||
GroupA_1 | GroupA_2 | GroupA_3 | GroupB_1 | GroupB_2 | GroupB_3 | ||
Total | 32 | 30 | 10 | 10 | 44 | 60 | |
Gender | Female | 16 | 14 | 6 | 9 | 20 | 20 |
Gender | Male | 16 | 16 | 4 | 1 | 24 | 40 |
Ethnicity | Hispanic or Latino | 2 | 5 | 6 | 1 | 4 | 5 |
Ethnicity | Not Hispanic or Latino | 30 | 25 | 4 | 9 | 40 | 55 |
i have been having no luck thus far. All I could this is to insert a row in the dataset for each group and then rename the original variable name
Both tables look like reports, not like datasets. Can you post the data used to create the first table? One thing is confusing: the total-line has 32 for GroupA_1, but the rows below sum-up to 64.
Hello. The original data looks like this:
Group_Category | Group | Total | Female | Male | Hispanic | NotHispanic |
Group A | GroupA_1 | 32 | 16 | 16 | 2 | 30 |
Group A | GroupA_2 | 30 | 14 | 16 | 5 | 25 |
Group A | GroupA_3 | 10 | 6 | 4 | 6 | 4 |
Group B | GroupB_1 | 10 | 9 | 1 | 1 | 9 |
Group B | GroupB_2 | 44 | 20 | 24 | 4 | 40 |
Group B | GroupB_3 | 60 | 20 | 40 | 5 | 55 |
Female + Male = Total
Hispanic + Not Hispanic = Total
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.