푸잉이의 기술블로그

SAS 5일 공부 본문

IT/SAS

SAS 5일 공부

data고수 2022. 7. 4. 02:45

복습 겸 시험 치고자 공부하는 5일 복습장!

 

#Day 1

 

라이브러리

: A SAS library contains one or more files that are defined, recognized, and accessible by SAS, and that are referenced and sotred as a unit.

 

라이브러리 할당/선언

: libname = library name의 약자

1. libname 2. aa 3. 'c:'\Users.' 4. ;

1. libname 선언 2. 라이브러리 이름 3. 윈도우 상의 주소/저장할 위치 (''로 표시) 4. 문장 끝;

 

데이터 셋 구성

a. 데이터

proc print data =work.aa;

run;

 

 

b. 데이터 설명 부분

1) proc contens data =work.aa;

    run;

 

2) proc dataset;

    contents data = work.aa;

    quit;

 

Proc print------------------------------------------------------

에서 사용하는 코딩: var, sum, label, where (where contains), ID

 

ex)

Title "Hello sas";

Footnote "bye sas";

Proc print data = work.aa  noobs  label ;

label var1 = '1_mouse';

where height > =180;

where name contains ' joh';

var height weight;

sum number;

run;

 

*var:work.aa에 있는 데이터 중 height weight 변수만 print

*sum: number 변수에 있는 모든 데이터 합산

*label: label 선언 시, label proc print data 옆에 두기

*where: where 조건에 해당하는 개체만 출력 (where 문장 두 번 사용 x )

    - where x=1 and x=2 는 오류 

    - Multiple place in ('서울', '부산, '대구');

    - name변수에서 joh 단어 있는 변수들만 출력

     ex) where name contains 'joh';

           where name ? 'john';

           where name not in ('john', 'sel');-> john, sel 포함 x

           where height between 150 and 160;

           where code like '%D' -> D로 끝나는 moved, called 형태

           where code like '--3'; -> 3글자 중 마지막 글자가 3

           where code like 'a_c%b_'; -> 젤 첫번째 글자가 a 세번째가 c 뒤에서 두번째가 b인 code

*Title/Footnote: 제목, 각주 생성

*noobs : obs 생성 x

 

1)Proc print data= work.cc;

   run;

 

2)proc print data = work.cc;

   id name;

   run;

-> 두개 차이점) 해당 변수가 obs 열을 대체한다. (obs 1, 2, 3대신- name으로 대체) 

 

 

Proc sort------------------------------------------------------

에서 사용하는 코딩: by, out, nodup, nodup key

 

ex)

proc sort data = work.aa nodup (nodup key) out =work.cc;

by height;

run;

proc print data=work.cc; run;

 

*height을 오름 차순으로 정렬 (오름차순이란 숫자 1, 2, 3, 영어 a, b, c)

*out은 원본 work.aa를 훼손 시키지 않기 위해 work.cc로 저장

*nodup은 모든 변수들이 동일한 개체들 제거 

*nodup key는 height 값이 같으면 같은 개체로 취급해서 중복 제거함! (승자는 젤 첨)

 

Proc contents------------------------------------------------------

 

ex) proc contents data =work.aa ;

run;

*work.aa에 대한 세부 내용 출력 (dataset에 대한 정보, descriptive portion)

 -> proc contents data =cups._all_ nodetails;은 cups라는 라이브러리에 대한 정보

 

Proc datasets------------------------------------------------------

 

ex) proc datasets;

contensts data= work.aa varnum;

quit;

*varnum은 변수 목록 순서를 원본데이터와 같이 출력

 

Proc import------------------------------------------------------

외부데이터를 불러드리는 step

dbms 1)엑셀은 dbms=xlsx, 2)txt는 dbms=txt 3)csv는 dbms=csv

 

1) ex) proc import datafile = "C:\USER\TEST1.xlsx" dbms =xlsx out =work.aa;

      sheet=car;

      getnames=yes;    

      run;

*xlsx 파일을 불러와서 work.aa로 저장

*dbms 불러들일 파일의 종류가 xlsx이에요 라는 선언

*sheet 는 car로 선택

*getnames는 젤 첫줄을 변수 명으로 사용할 것

 

2) ex) proc import datafile = "C:\USER\TEST1.txt" dbms =dlm out =work.aa;

      delimiter ='@';

      getnames=yes;    

      run;

*delimiter는 @이로 한다. (띄어쓰기는 @)

 

3) ex) proc import datafile = "C:\USER\TEST1.csv" dbms =csv out =work.aa;

      getnames=yes;    

      run;

*csv는 delimiter가 무조건 comma라서 delimiter 따로 선언안해도 됨

--------------------------------비슷------------------------

ex) data work.aa;

      infile "C:\USER\TEST1.CSV";

      input id name $ height;

      run;

      proc print data =work.aa; run;

 

Options-------------------------------------------------------------

ex) options number/nonumber/nodate/yearcutoff = 2017;

      proc print data = work.abc;

      run;

 

*options yearcutoff =2017는 2017년부터 해당 연도 읽음

*options firstobs = n: 처음 읽는 관측치 

*options obs =n; 마지막 관측치 n 번째

*options obs =max; 마지막 관측치 까지

ex) 데이터 양이 너무 많을 때, print에서 2-15까지만 보여줘 표시 방법 

 1) options firstobs =2 obs =15;

     proc print data = work.aa;

     run;

 2) proc print data = work.aa (firstobs =2 obs=15);

     run;

 

*현재 option 어떻게 되어있는지 보려면

ex) proc options; run; or proc options option = yearcutoff; run;

 

 

 

'IT > SAS' 카테고리의 다른 글

웹 개발 기본  (0) 2022.07.10
SAS 공부  (0) 2022.07.10
Comments