SAS Tech & Tip

BookmarkSubscribeRSS Feed

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

Started ‎02-28-2023 by
Modified ‎02-28-2023 by
Views 933

 

 

이 게시글은 PROC SQL의 SELECT문의 다양한 활용법에 대해서 알아봅니다.

 

7. 기존의 칼럼을 이용한 새로운 칼럼 생성

sashelp 라이브러리의 baseball 데이터에는 nRuns, nRBI, nBB 등의 칼럼이 존재합니다.

 

image.png

 

 

proc sql outobs=20;
select nAtBat, nHits, nHome, 
	nRuns+nRBI+nBB as total
from sashelp.baseball; 

 

image (1).png

 

 

nRuns, nRBI, nBB 3개의 칼럼을 더하여 total 이라는 새로운 칼럼을 만들어 낼

수 있습니다. 

SELECT statement 에서 연산자를 사용해서 새로운 칼럼을 만들고 AS statement 로 새로운 칼럼의 이름을 설정할 수 있습니다.

 

 

 

 

 8. Order By

 

SQL 을 통해서 데이터를 출력할 때 테이블이 입력된 순서대로 출력됩니다

데이터를 내림차순이나 오름차순으로 정렬하기 위해서는 ORDER BY statement 를 사용할 수 있습니다.

proc sql outobs=20;
select nAtBat, nHits, nHome, 
	nRuns+nRBI+nBB as total
from sashelp.baseball
order by total desc; 

 

image (2).png

 

 

Desc는 내림차순(큰값 > 작은값), ASC는 오름차순(작은값 > 큰값) 으로 Default 값으로 설정되어 있습니다.

#7.에서 total 값을 내림차순으로 정렬해보았습니다.

9. Title 작성하기 

 

테이블을 출력하고 제목을 작성할 수 있습니다.

제목을 작성하기 위해서는 

1) TITLE syntax를 PROC SQL 문 전에 작성을 해야하며

2) PROC SQL statement 와 SELECT statement 사이에 작성해야 합니다.

 

 

proc sql outobs=20;
title 'Score';
select nAtBat, nHits, nHome, 
	nRuns+nRBI+nBB as total
from sashelp.baseball
order by total desc; 

image (3).png

Version history
Last update:
‎02-28-2023 10:08 AM
Updated by:
Contributors

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

Article Labels
Article Tags