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
Want
Prov Codes
Thanks in advance
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;
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;
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.
Replace the keep statement with
drop cnt i codes;
@andreas_lds pointed out.
Just change the keep statement to a drop statement and specify the variable that was used temporarily.
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;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.