BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
cho16
Obsidian | Level 7

Hi,

 

I have multiple values on the column CODES and need to delete some of them which has 101,102,103,104,1110,

 

Prov   Codes

  • 101, 102,103,104,007
  • 101, 102,103,104,1110 ,007,008
  • 108,109,1110,1111

 

Want

 

Prov   Codes

  • 007
  • 007,008
  • 1111

Thanks in advance

1 ACCEPTED SOLUTION

Accepted Solutions
japelin
Rhodochrosite | Level 12

How about this code?

BTW, you have removed 108,109,1110 from 108,109,1110,1111.

Isn't it correct that it should be 108,109,1111?

 

data want;
  set have;
  length char $200;
  cnt=countw(codes,',');
  char='';
  do i=1 to cnt ;
    x=scan(codes,i);
    if x not in ('101','102','103','104','1110') then char=catx(',',char,x);
  end;
  keep char;
run;

 

 

View solution in original post

5 REPLIES 5
japelin
Rhodochrosite | Level 12

How about this code?

BTW, you have removed 108,109,1110 from 108,109,1110,1111.

Isn't it correct that it should be 108,109,1111?

 

data want;
  set have;
  length char $200;
  cnt=countw(codes,',');
  char='';
  do i=1 to cnt ;
    x=scan(codes,i);
    if x not in ('101','102','103','104','1110') then char=catx(',',char,x);
  end;
  keep char;
run;

 

 

cho16
Obsidian | Level 7

Yes Kawakami , you are right !

The code works perfect.

btw, how to include all other columns in the below code ..got error when I tried it.

andreas_lds
Jade | Level 19

Replace the keep statement with

drop cnt i codes;
japelin
Rhodochrosite | Level 12

@andreas_lds  pointed out.
Just change the keep statement to a drop statement and specify the variable that was used temporarily.

 

andreas_lds
Jade | Level 19

Alternative version, not fully tested:

data want2;
   set have;
   
   length reduced $ 100;
   
   codes = compress(codes);
   reduced = prxchange('s/(,?101)|(,?102)|(,?103)|(,?104)|(,?1110)//', -1, codes);
   reduced = substr(reduced, anydigit(reduced));
run;

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
  • 5 replies
  • 1342 views
  • 1 like
  • 3 in conversation