BookmarkSubscribeRSS Feed

[SAS 활용 노하우] PROC SQL - SELECT part2

Started ‎02-26-2023 by
Modified ‎02-26-2023 by
Views 1,760

 

이 게시글은 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%';

 image (6).png

 

 

 

6. 특정 문자열을 포함한/제외한 데이터 찾기 

특정 문자열을 포함하기 위해서는 where 절의 like도 사용할 수도 있고, PROC SQL에서 CONTAINS statement 도 사용할 수 있습니다.

 

proc sql;
select *
from odtut.products
where productname contains 'ch';

image (7).png

 

위는 where 절의 contains 문과 like 문이 동일한 결과를 출력하는 것을 확인할 수 있습니다.

 

 

 

proc sql;
select *
from odtut.products
where productname not in ('Tofu');

 

위의 예시는 productname 변수에서 tofu가 들어가지 않은 값만 출력한 것 입니다.

where 절의 not in을 활용해서 특정 값을 제외한 값을 출력할 수 있습니다.

 

image (8).png

Version history
Last update:
‎02-26-2023 06:03 PM
Updated by:
Contributors

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

Article Labels
Article Tags