SAS SQL procedure 정리

Hoya Jaeho Lee·2023년 11월 1일
0

SQL

목록 보기
5/5

SQL: 데이터의 검색, 요약, 정렬, 출력 등을 프로시저내에서 한번에 처리할 수 있는 장점이 있어 매우 효율적

Calculated의 활용:
Case when 명령어 조건식 사용때 select문에서 새로운 열 이용, Where문 사용때도 적용

proc sql;
select status, sex, height, weight,
height0.02 as height_m,
weight
0.4 as weight_kg,
calculated weight_kg / (calculated height_m)**2 as bmi,
case when calculated bmi le 18.5 & calculated bmi is not null then 'Underweight'
when calculated bmi gt 18.5 & calculated bmi lt 25 then 'Normal weight'
when calculated bmi ge 25 & calculated bmi lt 30 then 'Overweight'
when calculated bmi ge 30 then 'Obesity'
end as bmic
from sashelp.heart;quit;

Table/View

Create table ~as #새로운 table 형성
Create view ~as #화면에 결과를 나타낼뿐 원데이터를 수정, 저장하지 않음

Describe TABLE ~; # Log를 통해 내용 정리 확인
Describe VIEW ~;

행 삽입 방법 (데이터 내용 추가 방법)

Insert문을 이용한 행 끼워넣기 방법
1. Insert into ~ where 문 활용
2. Insert into ~ Set col1='a' col2='b'col3=2; #set문 활용
3. Values문을 활용한 방법
Insert Into ~Values ('a','b',2) Values ('c','d',3); # Values 문 활용
행의 삭제 -Delete문 활용

Column의 수정, 추가, 삭제

Column 추가할 때: alter table ADD #Col 추가
Column 지정 삭제할 때: alter table DROP #Col 삭제
Column에 해당하는 데이터 값들 업데이트: Update문을 활용한 column update
update ~ set col_update=col*1.1

Coalesce 함수의 활용

-결합때 공통으로 존재한는 데이터의 값만을 update
예시) select coalesce(a.score,b.score);
a left join b
on a.name=b.name;

profile
Biostatistics researcher Github: https://github.com/hoyajhl

0개의 댓글