BookmarkSubscribeRSS Feed

[SAS 프로그래밍 고수 백승민] boolean 값으로 표준화 하기 위하여 이중 부정(^^ or ~~) 사용

Started ‎06-11-2020 by
Modified ‎06-11-2020 by
Views 97

[참고] http://www.sascommunity.org/mwiki/index.php?title=Tips:Double_negatives_to_normalize_a_boolean_value...

이중 부정을 사용하여 수치형 값을 "boolean numeric" 값(0 과1) 으로 표준화 하기

/* create a flag var, found, which is 1 if the number 5 is found among the vars p1-p5; 0 otherwise */

WHICHN함수를 이용하여 숫자 5를 변수 P1~P5에서 검색하여서 위치를 찾은후에
이중 부정문을 사용하여서
 * 5가 존재하는 경우 1
 * 5가 존재하지 않는 경우 0
를 반환

data one;
  input p1-p5;
  found = ^^whichn(5, of p:);
cards;
1 2 3 4 5
6 7 8 9 0
;
run;
 
/* check */
proc print data=one noobs;
run;

[결과]
p1    p2    p3    p4    p5    found
 
 1     2     3     4     5      1
 6     7     8     9     0      0

만약 if문을 사용한다면
IF whichn(5, of p:) > 0 then found=1
else=0;

* 함수 : WHICHN(argument, value-1 <, value-2, ...>)
http://support.sas.com/documentation/cdl/en/lrdict/63026/HTML/default/viewer.htm#a003122573.htm
argument 의 값과 일치 하는 값을 검색하여 위치를 반환


불 [ Boolean ]

①영국의 수학자 조지 불(George Boole)이 창안한 불 대수의 이론과 규칙에 따른 연산에 관한 용어에 붙는 형용사.
②논리값을 다루는 연산에 관한 용어에 붙는 형용사. 불 대수는 X 또는 Y의 수치 계산이 아니라, 참 또는 거짓의 논리값을 다루기 때문에 이 용어가 쓰인다.
③일부 프로그램 언어에서의 기본적 데이터형의 하나. 많은 언어에서 참 또는 거짓의 논리값을 나타내는 불 데이터형을 직접 지원한다. 어떤 언어에서는 불값을 0(거짓)과 1(참)로 나타내는 정수 데이터형을 사용한다.

Version history
Last update:
‎06-11-2020 04:22 AM
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 Labels
Article Tags