BookmarkSubscribeRSS Feed
monday89
Fluorite | Level 6

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

8 REPLIES 8
PaigeMiller
Diamond | Level 26

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

--
Paige Miller
ballardw
Super User

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
Onyx | Level 15
Optionally you could do:
`g[i] =scan( g[i], 1, '(' );`

Bart
_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



ballardw
Super User

@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%.

 

monday89
Fluorite | Level 6

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

yabwon
Onyx | Level 15
do you have variable named "Group_" in your data?

Bart
_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



ballardw
Super User

@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.

yabwon
Onyx | Level 15
Good point.
Bart
_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



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