BookmarkSubscribeRSS Feed

문자형 변수(Character Variables) 4

Started ‎06-30-2025 by
Modified ‎06-30-2025 by
Views 695

SAS에서는 문자열을 연결하는 대표적인 함수 3가지가 있습니다.

  • CAT

  • CATS

  • CATX

CAT

 

가장 기본적인 문자열 연결함수입니다.

  • 문자열을 그대로 연결 (앞뒤 공백 제거 X)

  • 구분자를 자동으로 추가하지 않음.

# 기본 Syntax

 

 

CAT(text1, text2, ... , textn)

 

 

 

 

# 예시

 

 

data cat;
text1 = 'Believe ';
text2 = 'in';  
text3 = ' yourself.';

full_text = cat(text1, text2, text3);
put full_text;
run;

 

 

 

image.png

 

 

 

 

 

 

 

CATS

 

CAT 함수 + Strip 으로 공백을 제거하면서 문자열을 연결합니다.

  • 문자열의 앞뒤 공백을 제거하면서 연결합니다.

  • 구분자를 자동으로 추가하지 않습니다.

 

 

 

# 예시

 

 

data cat;
text1 = 'Believe ';
text2 = 'in';  
text3 = ' yourself.';

full_text = cats(text1, text2, text3);
put full_text;
run;

 

 

 

 image.png

 

 

 

 

 

text1 = 'Belive '에 공백과 text3 = ' yourself' 공백이 CATS 문을 사용하면서 모두 제거 되어 띄어쓰기 없이 'Beliveinyourself'라는 full_text로 출력이 되었습니다.

 

 

CATX

 

CAT 함수 +eXtra delimiter로 구분자를 지정하면서 문자열을 연결합니다.

3개의 함수 중에서 CATX가 가장 실용적이면서 많이 사용되는 함수입니다.

  • 첫번째 지정자로 구분자를 지정합니다.

  • 각 문자열의 앞,뒤 공백을 모두 제거합니다.

  • 결측값이 있으면 결측값은 무시합니다.

# 기본 syntax

 

CATX(delimiter, text1, text2, ..., textn)

 

 

# 예제1

 

data cat;
del = '-';
text1 = 'Believe ';
text2 = 'in';  
text3 = ' yourself.';

full_text = catx(del,text1, text2, text3);
put full_text;
run;

 

image.png

 

 

 

 

 

 

#예제2

 

data cat;
del = '-';
text1 = 'Believe ';
text2 = 'in';  
text3 = ' yourself.';
text4 = '';

full_text = catx(del,text1, text4 ,text2, text3);
put full_text;
run;

 

 

image.png

 

 

 

text4에 빈문자열이 있고, catx 문으로 del(구분자), text1 ~ text4를 연결하게 되면 text4인 빈문자열은 무시되고 문자열은 연결됩니다.

 

 

Contributors
Version history
Last update:
‎06-30-2025 09:54 AM
Updated by:

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

Article Labels
Article Tags