BookmarkSubscribeRSS Feed

찾기 & 바꾸기 Sample Code

Started ‎03-23-2021 by
Modified ‎03-23-2021 by
Views 530

엑셀의 찾기 및 바꾸기와 같은 기능을 구현해 보는 sample code 입니다. 

 

(1) HI, GD 등 영문 2글자로 표시된 모든 글자를 Hello, Good 등의 글자로 한번에 바꾸고 싶을때
(2) 0123010123 과 같은 10자리의숫자를 0123.01-0123 의 형식으로 5번째 자리에 점(.)을, 8번째 자리에 하이픈(-)을 특정 셀의 데이터들에 일괄적으로 넣고 싶을때


data test;

input a $10. c $10.;

datalines;

0123010123 HI

0123010123 HI

0123010123 HI

0123010123 HI

0123010123 GD

0123010123 HI

0123010123 GD

0123010123 HI

0123010123 HI

;

 

data result;

set test;

length b varchar(20);

length d varchar(20);

b = substr(a, 1, 4) || "." || substr(a, 5,2) || "-" || substr(a, 6,4);

if c = 'HI' then

d= tranwrd(c, 'HI', 'Hello');

else if c = 'GD' then

d= tranwrd(c, 'GD', 'Good');

run;

 

Version history
Last update:
‎03-23-2021 06:29 PM
Updated by:
Contributors

sas-innovate-white.png

🚨 Early Bird Rate Extended!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.

 

Lock in the best rate now before the price increases on April 1.

Register now!

Article Tags