Hello,
I would like to remove all th eHyphen / Space / Underlines in the dataset 'Text' but no compressing, just leave the number and letter with space formats. Thanks.
data Text;
infile datalines dsd;
input NewID : $15. TempID_1 : $15. TempID_2 : $15. TempID_3 : $15. TempID_4 : $15.;
datalines;
1156 IL, 89__46, 88--53, , ,
1487 KM, __8956, _78-52__, , ,
000-597, -1596_, 4113, , ,
C_ _-1156, 4986__, 0_0-0_8, , ,
208, 8M _ O23, , , ,
_21156--, 89 66, 885 - 2, 5 5 5 9, ,
;
You can use the TRANSLATE function. Example to replace underscores and hyphens with a blank:
z=translate(y,' ','_-');
You can use the TRANSLATE function. Example to replace underscores and hyphens with a blank:
z=translate(y,' ','_-');
Hi @ybz12003 ,
Does this output meet your expectations? If not, please specify the expected output.
best,
data Text;
infile datalines dsd;
input NewID : $15. TempID_1 : $15. TempID_2 : $15. TempID_3 : $15. TempID_4 : $15.;
datalines;
1156 IL, 89__46, 88--53, , ,
1487 KM, __8956, _78-52__, , ,
000-597, -1596_, 4113, , ,
C_ _-1156, 4986__, 0_0-0_8, , ,
208, 8M _ O23, , , ,
_21156--, 89 66, 885 - 2, 5 5 5 9, ,
;
data want;
set Text;
array _var (*) NewID TempID_1-TempID_4;
do i=1 to dim(_var);
_var(i) = prxchange('s/^\s|-|_|\s$/ /',-1,_var(i));
end;
drop i;
run;
To steal the logic from @ed_sas_member and use TRANSLATE()
data Text;
infile datalines dsd;
input NewID : $15. TempID_1 : $15. TempID_2 : $15. TempID_3 : $15. TempID_4 : $15.;
array _var(*) newid tempid_1-tempid_4;
do i=1 to dim(_var);
_var(i)=translate(_var(i),' ','-_');
end;
datalines;
1156 IL, 89__46, 88--53, , ,
1487 KM, __8956, _78-52__, , ,
000-597, -1596_, 4113, , ,
C_ _-1156, 4986__, 0_0-0_8, , ,
208, 8M _ O23, , , ,
_21156--, 89 66, 885 - 2, 5 5 5 9, ,
;
Thank you so much for all of wonderful help!
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 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: