BookmarkSubscribeRSS Feed

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

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

 

 

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

10. 테이블에 텍스트 넣기 

기존의 테이블에 가시적으로 일괄적인 텍스트를 삽입할 수 있습니다.

SELECT statement에서 칼럼과 같이 작성하면 됩니다.

 

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

 

image (5).png

 

 

 

'Total Score is' 라는 텍스트를 total 칼럼 앞에 삽입하기 위해, 작은 따옴표(' ')를 삽입하여 텍스트를 집어넣을 수 있습니다.

11. 데이터 summarizing

데이터를 aggregation하여 데이터를 추출하는 방법입니다.

SELECT 문에서 AVG function 을 사용해서 그룹별로 summarizing 할 수 있습니다. 

AVG function 이외에도 MEAN function 을 사용할 수 잇습니다. 

해당 그룹별로 summarizing 하기위해서는 GROUP BY statement 가 필수적으로 필요합니다.

 

 

proc sql;
select tv_reg, avg(bill) as averagebill
from air.organics
group by tv_reg;

 

image (6).png

 

 

12. 단일 칼럼 summarizing

그룹별로 summarizing이 아닌 단일 칼럼의 경우에도 아래와 같이 SELECT 문에서 summarizing을 실행할 수 있습니다.

 

 

proc sql;
select avg(bill) as averagebill
from air.organics;

image (7).png

 

 

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

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

Article Labels
Article Tags