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

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, , 
;

 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

You can use the TRANSLATE function. Example to replace underscores and hyphens with a blank:

 

   z=translate(y,' ','_-');

 

 

--
Paige Miller

View solution in original post

4 REPLIES 4
PaigeMiller
Diamond | Level 26

You can use the TRANSLATE function. Example to replace underscores and hyphens with a blank:

 

   z=translate(y,' ','_-');

 

 

--
Paige Miller
ed_sas_member
Meteorite | Level 14

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;

 

 

PaigeMiller
Diamond | Level 26

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, , 
;
--
Paige Miller
ybz12003
Rhodochrosite | Level 12

Thank you so much for all of wonderful help!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 5340 views
  • 4 likes
  • 3 in conversation