이 게시글은 PROC SQL의 SELECT문의 다양한 활용법에 대해서 알아봅니다.
4. 중복 데이터 삭제하기
SELECT 문에서 DISTINCT 문을 사용해서 중복행을 제거할 수 있습니다.
DISTINCT 문은 SELECT statement에 앞에서 적용됩니다.
proc sql;
select distinct *
from sashelp.air
order by 1;
5. 범위 설정
numeric 값이나 character 값을 범위를 설정할 수 있습니다.
BETWEEN ~ AND 연산자를 WHERE 절에서 사용해서 특정 변수의 값을 한정할 수 있습니다.
아래의 코드는 pricedata에서 sale 변수의 값이 350값과 400 사이의 데이터만을 출력합니다.
proc sql outobs=20;
select price
from sashelp.pricedata
where sale between 350 and 400;
아래의 코드는 odtut라이브러리의 products 데이터에서
product 변수에 'ch'가 들어간 데이터만 출력합니다.
proc sql outobs=20;
select *
from odtut.products
where productname like '%ch%';
6. 특정 문자열을 포함한/제외한 데이터 찾기
특정 문자열을 포함하기 위해서는 where 절의 like도 사용할 수도 있고, PROC SQL에서 CONTAINS statement 도 사용할 수 있습니다.
proc sql;
select *
from odtut.products
where productname contains 'ch';
위는 where 절의 contains 문과 like 문이 동일한 결과를 출력하는 것을 확인할 수 있습니다.
proc sql;
select *
from odtut.products
where productname not in ('Tofu');
위의 예시는 productname 변수에서 tofu가 들어가지 않은 값만 출력한 것 입니다.
where 절의 not in을 활용해서 특정 값을 제외한 값을 출력할 수 있습니다.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.