I have the following table below. What I would like to do is that
If category_1 = 'AAA' and category_2 = 'Yes' then Group_1 through Group_4 should delete '(100.0%)'.
Have
Category_1 | Category_2 | Group_1 | Group_2 | Group_3 | Group_4 |
AAA | Yes | 8 (100.0%) | 12 (100.0%) | 3 (100.0%) | 13 (100.0%) |
BBB | Yes | 2 (25.0%) | 6 (50.0%) | 1 (33.3%) | 10 (76.9%) |
BBB | No | 6 (75.0%) | 6 (50.0%) | 2 (66.7%) | 3 (23.1%) |
Want:
Category_1 | Category_2 | Group_1 | Group_2 | Group_3 | Group_4 |
AAA | Yes | 8 | 12 | 3 | 13 |
BBB | Yes | 2 (25.0%) | 6 (50.0%) | 1 (33.3%) | 10 (76.9%) |
BBB | No | 6 (75.0%) | 6 (50.0%) | 2 (66.7%) | 3 (23.1%) |
I am not sure how to do it. I tried catx and strip
You need to show us the actual SAS data set as SAS data step code, not some table representinng your data. We can't work with the tables you show.
The instructions to create a SAS data set as SAS data step code are here:
How to create a data step version of your data AKA generate sample data for forums
Maybe:
data want; set have; array g Group_1 - Group_4; if category_1 = 'AAA' and category_2= 'Yes' then do i=1 to dim(g); g[i] =tranwrd(g[i],'(100.0%)',''); end; drop i; run;
Generally when the same thing is to be done to multiple variables then think Array.
Personally I would likely go back to the step that created this marginally structured data and prevent the creation of such if at all possible. Putting 2 or more values into a single variable is quite often a difficult structure to work with.
@yabwon wrote:
Optionally you could do:
`g[i] =scan( g[i], 1, '(' );`
Bart
I thought of that but the OP doesn't say that all of the conditional variable values will always have the (100,0%).
If the value(s) were (45.0%) then scan would remove those as well but I understood the request to only remove 100%.
Hi. I tried the following:
data want;
set have;
array g Group_1 - Group_4;
if category_1 = 'AAA' and category_2= 'Yes' then do i=1 to dim(g);
g[i] =scan( g[i], 1, '(' );
end;
drop i;
run;
but i am getting errors for 'array g Group_1 - Group_4;' error message: Missing numeric suffix on a numbered variable list
@monday89 wrote:
Hi. I tried the following:
data want; set have; array g Group_1 - Group_4; if category_1 = 'AAA' and category_2= 'Yes' then do i=1 to dim(g); g[i] =scan( g[i], 1, '(' ); end; drop i; run;
but i am getting errors for 'array g Group_1 - Group_4;' error message: Missing numeric suffix on a numbered variable list
Your column headings show group_1 to 4. If those are not the variable names there is no way I can guess what the actual variables may be.
Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the <> icon or attached as text to show exactly what you have and that we can test code against.
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.