Программирование на языке sas/base · pdf...

Download Программирование на языке SAS/BASE · PDF fileПрограммирование на языке SAS Лекция 1. Основы. ЗвежинскийДмитрий,

If you can't read please download the document

Upload: trinhkhanh

Post on 08-Feb-2018

288 views

Category:

Documents


16 download

TRANSCRIPT

  • SAS

    1. .

    , SAS Russia/[email protected]

    . 1

    mailto:[email protected]

  • ?

    http://tiny.cc/msu_sas

    , .

    2

  • SAS University Edition

    http://www.sas.com/en_us/software/university-edition.html

    VirtualBox VMWare ,

    ( )

    . SAS, SAS U.

    3

    http://www.sas.com/en_us/software/university-edition.html

  • SAS University Edition

    4

  • ? (

    My Folders = ./SASUniversityEdition/myfolders ) (

    ). ~

    My Folders. .

    SAS U UTF, !

    5

  • (Log)

    Log . SAS.

    ( ). , .

    , Log.

    6

  • . SAS BASE

    (

    SAS, )

    DATA( )

    SAS PROC

    SAS(

    )

    SAS BASE

    . , .

    SAS. . (SAS data set).

    . ! ( ) (!) :

    DATA ( , , , ) PROC

    ( ) ( ). 7

  • SAS (datasets)

    () ,

    8 . 1 32767 .

    32 : _ a-z 0-9

    SAS ( , ) ( proc)

    ( -> Columns), : length (. - , ), name (), label (, , ), type (), format ( )

    SAS dataset , (SQL) 8

  • SAS () (*.sas7bdat)

    ( excel/access ) (engines).

    (xls csv SAS Studio; Code Snippets->Data->Import )

    SAS Studio SAS (

    ) ( , .), .

    9

  • SAS , .

    SAS , Work ( sas.exe) Sasuser ( ).

    , SAS ( , excel, access). , ( ) .

    10

  • SAS U

    1.

    ./SASUniversityEdition/myfolders My Folders.

    2. SAS Studio .

    11

  • :

    wizard (Tools->assign project library) .. ( libname):

    libname mylib c:\dir_with_data;mylib - : 0-9, a-z, _, , 8

    sas.exe ( SAS U - Sign out, )

    (c:\dir_with_data\testdataset.sas7bdat), 2- ( ):

    mylib.testdataset Work Server list, :

    proc contents data=sasuser._all_;run;

    SAS U

    12

  • SAS Base options linesize=95 pagesize=52; data work.NewSalesEmps; length First_Name $ 12 Last_Name $ 18 Job_Title $ 25; infile 'newemps.csv' dlm=','; input First_Name $ Last_Name $ Job_Title $ Salary; run;

    proc print data=work.NewSalesEmps; run; proc means data=work.NewSalesEmps; class Job_Title; var Salary; run;

    13

  • SAS Base

    , SAS (#include)

    , SAS

    , ( data, proc)

    ( RUN)

    ; run;,

    quit;, (

    , )

    14

  • (- pdf)http://support.sas.com/documentation

    1) SAS BASE ( )

    2) overview , ( PROC)

    3) examples

    4) *) SUGI ( )*) SAS

    :SAS/STAT(R) 9.3 User's GuideSAS(R) 9.3 Functions and CALL Routines: ReferenceBase SAS(R) 9.3 Procedures Guide, Second EditionSAS(R) 9.3 SQL Procedure User's Guide 15

  • DATA ,

    SQL (wiki: 1986 SQL ANSI, SAS 1966, 1976 ).

    DATA SQL (SQL , DATA ). .

    DATA SQL ( ), , .

    SAS ( , , , , , , , , , , ...).

    , DATA. DATA STEP: SAS(R) 9.3 Language Reference: Concepts, Second Edition -> DATA Step

    Concepts SAS(R) 9.3 Language Reference: Concepts, Second Edition -> Dictionary of

    Language Elements -> SAS Data Set Options 16

  • DATA :

    ?(. Overview of DATA Step Processing: Flow of Action)

    data employees; set employee_list; run;

    1) : - - (Program Data Vector,

    PDV) , () , .

    - ( ) ( , , .)

    17

  • ?

    2) data. () SET , .

    : ?

    DATA data employees; set employee_list; run;

    PDV:( )

    VAR1 VAR2 VAR3

    employees:( )

    ,

    Data Set Name Observations

    Member Type Variables ..

    Engine .. Indexes

    Created Observation Length

    Last Modified Deleted Observations

    VAR1 (Num) VAR2 (Char) VAR3 (Num)

    18

  • SET

    data employees; set employee_list; run;

    PDVVAR1 VAR2 VAR3

    employeesData Set Name Observations Member Type Variables ..Engine .. Indexes Created Observation Length Last Modified Deleted Observations

    VAR1 (Num) VAR2 (Char) VAR3 (Num)

    Employee_listData Set Name Observations Member Type Variables ..Engine .. Indexes Created Observation Length Last Modified Deleted Observations

    VAR1 (Num) VAR2 (Char) VAR3 (Num)

    1 AAA 200

    2 BBB 201

    3 CCC 202

    0. . 1. Set =

    Employee_list PDV2. Output =

    PDV employees3. Return =

    DATA

    1 AAA 200

    1 AAA 200

    2 BBB 201

    2 BBB 201

    3 CCC 202

    3 CCC 202

    19

  • data employees; set employee_list; where age GT

    < LT

    >= GE

  • data employees; set employee_list; where age

  • 1. DATA: IF expression THEN do;

    ; ;;

    end;ELSE do;

    ;end;

    2. ( switch-case):SELECT;

    WHEN (when-expression-1) statement;

    END;

    select-when .22

  • DATA ( ):

    Program Data Vector, , DATA. Bonus employee_list , PDV .

    ?1. (., , , )2. ,

    (, ), .

    data employees; set employee_list; if upcase(Country)='US' then Bonus = 500; else Bonus=0; run;

    * . SAS(R) 9.3 Language Reference: Dictionary 23

  • * , function-name (argument-1)function-name (OF -) DATA PROC (, -) :SUM(argument,argument,... ) ( .)Sum + . a1 a2 temp?

    UPCASE(argument) PUT(source, format.) (format)INPUT(source,informat.) (informat)

    * : SAS(R) 9.3 Functions and CALL Routines: Reference

    B (Num) C (Num)

    . 1

    data temp; set in_tab; a1=b+c; a2=sum(b,c); run;

    in_tab

    24

    http://support.sas.com/documentation/cdl/en/lefunctionsref/63354/HTML/default/n0zxive1z1ctqin12w06c85jfigd.htm%23p16bpq59kyh73bn1agvwv222t09nhttp://support.sas.com/documentation/cdl/en/lefunctionsref/63354/HTML/default/n0zxive1z1ctqin12w06c85jfigd.htm%23p16bpq59kyh73bn1agvwv222t09nhttp://support.sas.com/documentation/cdl/en/lefunctionsref/63354/HTML/default/p0ilulfezdl4ykn17295t8tnh4xc.htm%23n0mwfg8vvbjoy6n14oiraqjuwpf3http://support.sas.com/documentation/cdl/en/lefunctionsref/63354/HTML/default/n0mlfb88dkhbmun1x08qbh5xbs7e.htm%23p04xmxs2j5ayzpn1ilorfb2gvxhlhttp://support.sas.com/documentation/cdl/en/lefunctionsref/63354/HTML/default/n0mlfb88dkhbmun1x08qbh5xbs7e.htm%23p0wfflof7qhl7in1cv1pagjhakiphttp://support.sas.com/documentation/cdl/en/lefunctionsref/63354/HTML/default/p19en16vskd2vhn1vwmxpxnglxxs.htm%23p0sle4a2cvrbk3n1g9j8hb5ur3pxhttp://support.sas.com/documentation/cdl/en/lefunctionsref/63354/HTML/default/p19en16vskd2vhn1vwmxpxnglxxs.htm%23p04br22krqb3edn1qlr7bf5vj8fm

  • SAS 01 1960 / (datetime) 01 1960 ( ) , , :

    DATE SASDATEPART SAS /DATETIME / (timestamp)DAY : day ( 01jan2013d ) -> 1 ; day (19359) -> 1DHMS / (datetime) , , , .HMS SAS , HOUR /INTCK , (, , )INTNX , / , SASMDY , , : Mdy(1,1,2013) -> 19359MINUTE /MONTH QTR () SAS.TIME SASTIMEPART , , TODAY WEEK WEEKDAY YEAR YRDIF Returns the difference in years between two dates according to specified day count conventions; returns a persons age.

    25

    http://support.sas.com/documentation/cdl/en/lefunctionsref/63354/HTML/default/p0ht19bal6q7den1brjimarp1oo7.htmhttp://support.sas.com/documentation/cdl/en/lefunctionsref/63354/HTML/default/p0rttbu7w62xgzn1damccyuwpld8.htmhttp://support.sas.com/documentation/cdl/en/lefunctionsref/63354/HTML/default/n0d1c4j8iqvqsen1r4lq8plq8atb.htmhttp://support.sas.com/documentation/cdl/en/lefunctionsref/63354/HTML/default/n1unol18vcga6vn12vjvdhw1l8je.htmhttp://support.sas.com/documentation/cdl/en/lefunctionsref/63354/HTML/default/p1b9d1kbo0czoxn1ouj1kcxwqzn1.htmhttp://support.sas.com/documentation/cdl/en/lefunctionsref/63354/HTML/default/n1oc359bvmqub9n1iavw6u3we8oi.htmhttp://support.sas.com/documentation/cdl/en/lefunctionsref/63354/HTML/default/p1wo6rbbreow6cn0zig8ajg31qq8.htmhttp://support.sas.com/documentation/cdl/en/lefunctionsref/63354/HTML/default/p1md4mx2crzfaqn14va8kt7qvfhr.htmhttp://support.sas.com/documentation/cdl/en/lefunctionsref/63354/HTML/default/p10v3sa3i4kfxfn1sovhi5xzxh8n.htmhttp://support.sas.com/documentation/cdl/en/lefunctionsref/63354/HTML/default/p0bo5thbfrcab1n1menkqxq2suiv.htmhttp://support.sas.com/documentation/cdl/en/lefunctionsref/63354/HTML/default/n0jfimqujrjz3on1b0ozp6ctrczb.htmhttp://support.sas.com/documentation/cdl/en/lefunctionsref/63354/HTML/default/n0bn6385z4pweqn1qrpmklqtln99.htmhttp://support.sas.com/documentation/cdl/en/lefunctionsref/63354/HTML/default/n16ms5xazz0m0on1wd3f9p46s6xa.htmhttp://support.sas.com/documentation/cdl/en/lefunctionsref/63354/HTML/default/p096aldg7bq6qsn10m4044qbslka.htmhttp://support.sas.com/documentation/cdl/en/lefunctionsref/63354/HTML/default/n1dz873p380nc0n1ok2sfyl3dqhv.htmhttp