Top Banner

of 121

Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

Feb 03, 2018

Download

Documents

Raj Kumar
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    1/121

    Step by step

    guide to LearnSASVenkat Reddy

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    2/121

    Contents

    What is SAS?

    Step-1: SAS windowing environment

    Step-: SAS !atasets and Variab"es

    Step-#: $mporting data into SAS Step-%: &asi' (ro'edures and )un'tions

    Step-*: Combining !atasets in SAS

    +e,t Steps

    Ve

    nkata

    Reddy

    -onasan

    i

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    3/121

    &e.ore you start/

    (re Re0uisites &asi' data base know"edge

    &asi' idea on Ana"yti's and App"i'ations

    Windows S with minimum 2& RA3

    SAS so.tware

    !is'"aimer 4his presentation is 5ust '"ass notes6 4he best way to

    treat this is as a high-"eve" summary7

    4he a'tua" session went more in depth and'ontained other in.ormation6

    3ost o. this materia" was written as in.orma" notes8not intended .or pub"i'ation

    Ve

    nkata

    Reddy

    -onasan

    i

    #

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    4/121

    What is SAS?

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    5/121

    Ana"ysis App"i'ations

    (redi'ting what wi"" be the right segment .or amarketing 'ampaign 9 !e'ision 4rees

    (redi'ting the "oan repay 'apa'ity o. a 'ustomer 9Logisti' Regression

    )ore'asting the revenue numbers .or a produ't -AR$3A

    $denti.ying .raud '"aims in hea"th'are insuran'e 9C"uster Ana"ysis

    4he re'ommendation engine that predi'ts thebest produ't that interests the user - +eura"networks

    (redi'ting the sa"es numbers based on ma'roe'onomi' data 9 Regression ana"ysis

    Ve

    nkata

    Reddy

    -onasan

    i

    *

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    6/121

    What is 2auss markov theorem

    Ve

    nkata

    Reddy

    -onasan

    i

    4he above theorem is used ;nd the regression estimates

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    7/121

    A"" ana"yti's a"gorithms are'omp"i'ated We need pre written "ibraries or 'odes to per.orm

    ana"yti'a" operations

    &e"ow too"s wi"" make ana"yti's easy SAS

    RS(SS

    3at"ab

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    8/121

    3ain (hases in "earningana"yti's too"

    Ve

    nkata

    Reddy

    -onasan

    i

    >

    1) Basics $ntrodu'tion to the

    too" Coding and debugging $mportant .eatures

    and "imitations

    2) DataHandling $mporting the data !ata manimpu"ations

    'reating 'a"'u"ated;e"ds

    !ata 3erging

    3) Functionsand Algorithms

    &asi' and Advan'ed.un'tions

    Statisti'a" te'hni0uesand a"gorithms

    &asi' Reporting ande,porting the resu"ts

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    9/121

    Step-1: SAS windowingenvironment

    Ve

    nkata

    Reddy

    -onasan

    i

    @

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    10/121

    Contents

    $ntrodu'tion to SAS

    A''essing SAS

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    11/121

    What is SAS?

    Co""e'tion o. modu"es that are used to pro'ess andana"yBe data6

    !eve"oped in the early 1970s at North Carolinatate !ni"ersity

    rigina""y intended .or management and ana"ysiso. agri'u"tura" ;e"d e,periments

    +ow the most wide"y used statisti'a" so.tware

    sed to stand .or DStatisti'a" Ana"ysis SystemE8

    now it is not an a'ronym .or anything (ronoun'ed DsassE8 not spe""ed out as three

    "etters6

    Ve

    nkata

    Reddy

    -onasan

    i

    11

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    12/121

    Various $ndustries useSAS

    Casinos

    Communi'ations

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    13/121

    A''essing SAS

    Ve

    nkata

    Reddy

    -onasani

    1#

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    14/121

    A''essing SAS 9 on"inu,Goptiona"H16 4ype sas 6 4his opens the SAS Ddisp"ay managerE8

    whi'h 'onsists o. three windows Gprogram8 "og8 andoutputH6 Some pro'edures must be run .rom thedisp"ay manager6

    6 4ype sas -nodms 6 Iou wi"" be prompted .or ea'h SASstatement8 and output wi"" s'ro"" by on the s'reen6

    #6 4ype sas -stdio 6 SAS wi"" a't "ike a standard +$Jprogram8 e,pe'ting input .rom standard input8sending the "og to standard error8 and the output to

    standard output7%6 4ype sas ;"ename6sas 6 4his is the bat'h mode o.

    SAS -your program is read .rom ;"ename6sas8 the "oggoes to ;"ename6"og and the output goes to;"ename6"st6

    Ve

    nkata

    Reddy

    -onasani

    1%

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    15/121

    4he SAS S'reen

    Ve

    nkata

    Reddy

    -onasani

    1*

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    16/121

    4he SAS S'reen - $

    Ve

    nkata

    Reddy

    -onasani

    1

    Log Window

    Explorer

    Window

    Editor Window

    Output Window

    Results

    Window

    (not shown)

    Run button click on this button

    to run SAS code

    Click here or

    SAS help!ew Window button

    S"#e button

    $ool b"r si%il"r

    to Windows "pplic"tions

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    17/121

    Lab:

    pen SAS .rom start button6 $denti.y be"ow windows in SAS

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    18/121

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    19/121

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    20/121

    Log window

    Ve

    nkata

    Reddy

    -onasani

    Where is "og window in SAS?

    16 4he !ebug window6 !isp"ays the messages

    about SAS session and

    the program that issubmitted6

    Write this s'ript in editor andsee the "og ;"e7

    procprint

    data=sashelp.airr;

    run;

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    21/121

    utputs window

    Ve

    nkata

    Reddy

    -onasani

    1

    16 !isp"ays the "isting output in theoutput window

    6 $t automati'a""y opens or moves tothe .ront o. disp"ay when output is'reated6

    Write this s'ript in editor and seeoutput ;"e7

    procprintdata=sashelp.air;run;

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    22/121

    Resu"ts window

    Ve

    nkata

    Reddy

    -onasani

    16 Fe"ps navigate and manageoutput

    6 View8 save8 and print individua"items o. output6

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    23/121

    Comments and Fe"p menu

    Ve

    nkata

    Reddy

    -onasani

    #

    4here are two sty"es o. 'omments you 'an use:16 ne starts with an asterisk GKH and ends with a

    semi'o"on G7H6

    6 4he other sty"e starts with a s"ash asterisk GKH andends with an asterisk s"ash GKH6

    #ther o$tions% Resu"ts in htm"

    output

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    24/121

    Lab: 3y ;rst SAS (rogram

    3y ;rst SAS program9 DFe""o wor"dE

    pro' print dataMsashe"p6air7

    run7

    Submit the program

    Write this SAS s'ript in your editordataincome_data;

    Inputincome expenses;

    Cards;

    1200 1000

    9000 600

    ;run;

    Procprintdata=income_data;

    Run;

    Ve

    nkata

    Reddy

    -onasani

    %

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    25/121

    Lab

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    26/121

    Lab: 3y ;rst SAS program

    Run be"ow 'ode

    pro' print dataMsashe"p6airr7

    run7

    Fow to diagnose 'orre't errors

    Run be"ow 'odepro' 'ontent dataMsashe"p6air7

    run7

    $denti.y the errors i. any

    (rint in'omeNdata C"ose SAS open it again

    (rint in'omeNdata

    Ve

    nkata

    Reddy

    -onasani

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    27/121

    SAS Libraries

    &y de;ning a "ibrary8 you indi'ate the "o'ation o. yourSAS ;"es to SAS

    Co""e'tion o. SAS ;"es su'h as SAS data sets and'ata"ogs

    4o a''ess a "ibrary8 you need to assign it a name Ga"so

    known as a "ibre.8 or "ibrary re.eren'eH A.ter assigning a "ibrary name youO"" work with SAS

    data sets in a "ibrary $n the Windows and ni, environments8 SAS "ibrary is

    typi'a""y a group o. SAS ;"es in the same .o"der or

    dire'tory6 Fow to de;ne a "ibrary? sing $ntera'tive window Libname Statement

    Ve

    nkata

    Reddy

    -onasa

    ni

    =

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    28/121

    4emporary and permanent"ibraries

    Ve

    nkata

    Reddy

    -onasa

    ni

    >

    &em$ 'i(rary Storing ;"es temporari"y

    $. you donOt spe'i.y a "ibraryname when you 'reate a

    ;"eor

    $. you spe'i.y the "ibraryname WR

    4hen the ;"e is stored in the

    temporary SAS data "ibrary

    Last on"y .or the 'urrentSAS session

    ermanent li(rary Storing ;"es

    permanent"y

    Spe'i.y a "ibrary nameother than the de.au"t"ibrary name Work

    Avai"ab"e duringsubse0uent SASsessions

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    29/121

    !e;ning a "ibrary -2$

    !e;ne a "ibrary name usingintera'tive window n the too"bar8 '"i'k the +ew Library too"

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    30/121

    Libname Statement

    Write a statement in a editor window

    Synta,

    L$&+A3< "ibre. OSAS-"ibraryQ 7

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    31/121

    Ru"es .or assigning aLibrary16 Limited to > 'hara'ters "ong

    6 3ust start with "etter orunders'ore on"y

    #6 Can be a 'ombination o. "etters8numbers and unders'ore

    Venkata

    Reddy

    -onasa

    ni

    #1

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    32/121

    Re.eren'ing ;"es in SASLibrariesAs we know8 to re.eren'e a SAS ;"e we need to assign a libref

    G"ibrary re.eren'eH to the SAS "ibrary in whi'h the ;"e is

    stored6 Re.eren'ing ;"es .rom permanent "ibrary:

    4o re.eren'e permanent SAS data set8 you use two-"eve"

    name6 libref.lename 4he libref is name o. the SAS data "ibrary that 'ontains the

    ;"e6 4he lenameis the name o. the ;"e itse".6

    A period separates the librefand lename6

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    33/121

    SAS de.au"t "ibraries GSe".H

    )o""owing "ibraries are automati'a""y assigned ea'h timeyou start SAS

    Sashe"p: (ermanent "ibrary Contains samp"e data and other ;"es that 'ontro"

    how SAS works at our site6 4his is a read-on"y "ibrary

    Sasuser: (ermanent "ibrary Contains SAS ;"es that store persona" settings our

    own ;"es

    Work: 4emporary "ibrary Last on"y .or the 'urrent SAS session

    Venkata

    Reddy

    -onasa

    ni

    ##

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    34/121

    Lab

    (rint a data ;"e .rom SAS de.au"t "ibrary

    (ro' print dataM UP 7 run7

    (rint a data ;"e .rom SASuser "ibrary

    (rint a dataset .rom work "ibrary6

    4ry work6 without work6 Create a new "ibrary DNdataNE

    Create a new "ibrary D#dataNE

    Create a new "ibrary DdataE

    Venkata

    Reddy

    -onasa

    ni

    #%

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    35/121

    Step-: SAS datasetsand variab"es

    Venkata

    Reddy

    -onasa

    ni

    #*

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    36/121

    Contents

    SAS programs

    !ata step

    (RC Step

    Writing a SAS program and debugging it

    SAS !ata sets !ata sets properties

    Variab"es in a data set

    4ypes o. variab"es

    Attributes o. variab"es

    Create data using !ata statement Venkata

    Reddy

    -onasa

    ni

    #

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    37/121

    SAS (rogram

    Se0uen'e o. statements e,e'uted in order

    sed to a''ess8 manage8 ana"yBe and present thedata

    Contains statements8 e,pressions8 .un'tions and

    CALL routines8 options8 .ormats8 and in.ormats Simp"i;ed programming with bui"t in programs

    known as A rocedures Gpre written 'odesH (RC R

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    38/121

    Chara'teristi's and "ayout

    SAS programs are made up o. SAS statements6

    A SAS statement has two important'hara'teristi's:

    16 $t usua""y begins with a SAS keyword66 $t a"ways ends with a semi'o"on

    Layout o. SAS program:16 4hey 'an begin and end anywhere on a "ine

    6 ne statement 'an 'ontinue over severa" "ines

    #6 Severa" statements 'an be on a "ine6

    %6 SAS statements are +4 'ase sensitive6

    *6 &"anks or spe'ia" 'hara'ters separate thewords in a SAS statement6

    Venkata

    Reddy

    -onasa

    ni

    #>

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    39/121

    Lab

    (rint a dataset in SAS he"p "ibrary

    (ro' print dataMUP7 run7

    4ry these properties o. SAS statements

    16 4hey 'an begin and end anywhere on a "ine -

    4ry it6 ne statement 'an 'ontinue over severa"

    "ines - 4ry it

    #6 Severa" statements 'an be on a "ine6 - 4ry it

    %6 SAS statements are +4 'ase sensitive6 - 4ry

    it Venkata

    Reddy

    -onasa

    ni

    #@

    C t . SAS

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    40/121

    Components o. SAS(rograms

    SAS programs are 'onstru'ted .rom two basi' bui"dingb"o'ks:

    16 !A4A steps

    6 (RC steps 4hese two types o. steps8 a"one or 'ombined8 .orm a""

    SAS programs6 2enera""y8 a step ends with a R+ statement or when a

    new !A4A or (RC step begins6

    Venkata

    Reddy

    -onasa

    ni

    %

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    41/121

    !A4A step

    &egins with the keyword !A4A

    Creates or modi;es the data set

    (rodu'es 'ustom designed reports

    sing data step we 'an

    (ut our data into a SAS data set

    Compute va"ues 'reate new ;e"ds

    Che'k .or and 'orre't errors in our data

    (rodu'e new SAS data sets by sub setting8 merging8and updating e,isting data sets

    Venkata

    Reddy

    -onasa

    ni

    %1

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    42/121

    Creating a SAS data

    data U"ibnameP6UdatasetnameP7

    $nput Uvar1P UvarP/6UvarpP7

    Cards7

    v11 v1 /6vp1

    ////66v1n vn /6vpn

    7

    run7

    Venkata

    Reddy

    -onasa

    ni

    %

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    43/121

    Creating a SAS data

    V

    enkata

    Reddy

    -onasa

    ni

    %#

    datamylib.stock;

    inputolume price;

    cards;

    1200 1!

    1!00 1!."

    12"0 161!#0 1$."

    1290 1%

    1609 19."

    1%09 1#

    112$ 16.";

    run;

    ! t ti . SAS d t

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    44/121

    !ata portion o. SAS dataset

    bservations GRowsH: Co""e'tions o. data va"ues

    that usua""y re"ate to asing"e ob5e't

    Can store any number o.

    observations6

    Variab"es GCo"umnsH: Co""e'tions o. va"ues that

    des'ribe a parti'u"ar

    'hara'teristi' Can store thousands o.

    variab"es6

    V

    enkata

    Reddy

    -onasa

    ni

    %%

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    45/121

    Lab

    se data step and 'reate a dataset namedDrea""ybigdatasetnamethis1#%*=>E7

    se data step and 'reate a dataset namedD1#dataE7

    se data step and 'reate a dataset namedDTdataE7

    se data step and 'reate a dataset namedDNdataE7

    se data step and 'reate a dataset namedDNdata1#E7

    V

    enkata

    Reddy

    -onasa

    ni

    %*

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    46/121

    SAS !ataset name ru"es

    16 Can be 1 to # 'hara'ters "ong

    6 3ust begin with a "etter GA98 either upper'ase or"ower'aseH or an unders'ore G N H

    #6 Can be a 'ombination o. numbers8 "etters8 orunders'ores6

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    47/121

    Lab

    se data step and 'reate a variab"e namedDrea""ybigvarnamethis1#%*=>@1111E7 in adataset

    se data step and 'reate a variab"e named

    D1#varE7 se data step and 'reate a variab"e named

    DTvarE7

    se data step and 'reate a variab"e namedDNvarE7

    se data step and 'reate a variab"e namedDNvar1#E7

    V

    enkata

    Reddy

    -onasa

    ni

    %=

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    48/121

    SAS Variab"es

    Co"umns in the SAS datasets are 'a""ed SASvariab"es6Attributes o. SAS variab"es: Attribute in.ormation in'"udes

    the variab"eOs

    16 4ype

    6 Length

    #6 )ormat

    %6 $n.ormat

    *6 Labe"6

    SAS variab"e name ru"es: GSame as SAS dataset nameH

    6 Limited to # 'hara'ters "ong=6 3ust start with "etter or unders'ore

    >6 Can be a 'ombination o. "etters Gpper'ase "ower'ase8A-H 8 numbers and unders'ore

    V

    enkata

    Reddy

    -onasa

    ni

    %>

    L b C ti "

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    49/121

    Lab: Creating a samp"edataset using s'ript Run be"ow s'riptDatastudent;

    inputhei&ht 'ei&ht;

    Cards;

    120 ""

    1$$ #01!0 #%

    1$" 69

    ;

    Run;

    See the properties o. the 'reated data8 pro' 'ontents

    Add a new variab"e Qname to the above dataset

    What is the error? Gse TH

    See pro' 'ontents data

    (rint data

    V

    enkata

    Reddy

    -onasa

    ni

    %@

    3ain Attributes o. a

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    50/121

    3ain Attributes o. avariab"e Length:

    Chara'ter variab"es 'an be up to #8== bytes "ong6 A"" numeri' variab"es have a de.au"t "ength o. >6

    Labe": Consists o. des'riptive te,t up to * 'hara'ters "ong Labe"s are used instead o. variab"e names in some reports

    Labe"s are used .or the 'o"umn headings in the V$

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    51/121

    3ain types o. SASvariab"es

    Chara'ter variab"es:16 Can 'ontain any va"ue

    6 se &"ank to represent the missing va"ues

    #6 Can be up to #

    +umeri' variab"es:%6 Can 'ontain on"y numeri' va"ues

    G digits through @8 Y8-868 < or s'ienti;' notationsH

    6 se a sing"e period G6H to represent the missing va"ues

    #6 Fave a de.au"t "ength o. >6

    %6 +umeri' va"ues are stored as Zoating point number as> bytes o. storage8 un"ess you spe'i.y another "ength6 V

    enkata

    Reddy

    -onasa

    ni

    *1

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    52/121

    Step-#: $mporting datainto SAS

    V

    enkata

    Reddy

    -onasa

    ni

    *

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    53/121

    Contents

    !ata set 'reation using SAS programGdata stepH

    sing import wiBard $mporting

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    54/121

    Reading data using importwiBard

    V

    enkata

    Reddy

    -onasa

    ni

    *%

    &

    '

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    55/121

    Lab

    $mport SurveyNdata .rom SurveyNdata6,"s ;"e

    +ame the output ;"e as surveyN17

    $mport the ;"e into work "ibrary 'urrent "ibrary

    (rint the 'ontents o. the data

    Are a"" the variab"es present in the SAS dataset? $mport QCustNsurveyNo"d data .rom

    SurveyNdata16,"s

    V

    enkata

    Reddy

    -onasa

    ni

    **

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    56/121

    $mport CSV and 4A& ;"es

    V

    enkata

    Reddy

    -onasa

    ni

    *

    &

    '

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    57/121

    Lab

    $mport '"ientNdata6'sv ;"e

    +ame the output ;"e as '"ientN17

    $mport the ;"e into work "ibrary 'urrent "ibrary

    (rint the 'ontents o. the data

    Are a"" the variab"es present in the SAS dataset? $mport '"inetNmanager6t,t ;"e

    $mport pri'e web6'sv ;"e

    See the 'ontents

    a"e the im$ort code in local *older Venkata

    Reddy

    -onasa

    ni

    *=

    R di d t t i Q(RC

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    58/121

    Reading data sets using Q(RCimport

    ROC *+OR$ ,A$A-*LE. /0location of file12s"%ple3d"t"4cs#5

    O6$. testd"t4excelSAS&

    ,7+S.CS8

    RELACE9

    R6!9

    Where

    DATAFILEis the n"%e "nd the loc"tion o ile :ou w"nt to re"d4

    OUTis the n"%e o the SAS d"t" set :ou w"nt to cre"te

    DBMS is identifier; speciies the t:pe o d"t" to i%port4 8"lid identiiers ordeli%ited iles "re ,L+;

    Lab: sing (ro' $mport

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    59/121

    Lab: sing (ro' $mports'ript $mport Fea"th'are data

    (rint the 'ontents o. the data

    Are a"" the variab"es present in the SAS dataset?

    4ry with and without rep"a'e options

    $mport 'ars data $mport 'redit risk6t,t data

    V

    enkata

    Reddy

    -onasani

    *@

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    60/121

    Working with !& ;"es

    V

    enkata

    Reddy

    -onasani

    What i. we have a"" these tab"es in one database?

    1

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    61/121

    Lab

    Create a "ibrary out o. A""NSurveyN!&6mdb

    (rint the 'ontents o. the ;"es

    Copy re"evant tab"es into your "ibrary

    (rint '"ientNmanager data

    4ry opening a''ess ;"e using a''ess now

    V

    enkata

    Reddy

    -onasani

    1

    Reading data .rom SAS

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    62/121

    Reading data .rom SASdatasets =ow to cre"te " new SAS d"t" set out o SAS d"t" set>

    =ow do we cre"te sur#e:' ro% sur#e: d"t">

    ,"t" libn"%e4new9

    Set libn"%e4old9

    Run9

    V

    enkata

    Reddy

    -onasani

    Lab: Creating new

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    63/121

    Lab: Creating newvariab"es Create a new dataset and add a new variab"e

    s'ore1 GResponse Y [ua"ityHdata'ork.surey_2;

    set'ork.surey;

    score1=(response)*uality+,2;

    run;

    Create a new variab"e diX8 the diXeren'e betweenovera"" rating and s'ore1

    pdate the same dataset with a new variab"einterNs'ore whi'h is average o. Communi'ation8Response8 [ua"ity s'ore

    (rint a"" the observations with overa"" s'ore graterthan than or e0ua" to %

    V

    enkata

    Reddy

    -onasani

    #

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    64/121

    3anipu"ating SAS datasets Variab"es

    V

    enkata

    Reddy

    -onasani

    %

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    65/121

    Contents

    Re'ap

    Creating and managing variab"es

    !rop keep statements

    Conditiona" data pro'essing

    SAS .un'tions

    V

    enkata

    Reddy

    -onasani

    *

    Lab: Creating new

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    66/121

    Lab: Creating newvariab"es Create a new dataset and add a new variab"e

    s'ore1 GResponse Y [ua"ityHdata'ork.surey_2;

    set'ork.surey;

    score1=(response)*uality+,2;

    run;

    Create a new variab"e diX8 the diXeren'e betweenovera"" rating and s'ore1

    pdate the same dataset with a new variab"einterNs'ore whi'h is average o. Communi'ation8Response8 [ua"ity s'ore

    (rint a"" the observations with overa"" s'ore graterthan than or e0ua" to %

    V

    enkata

    Reddy

    -onasani

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    67/121

    Re'ap

    Create a new "ibrary

    What are the a"ready e,isting datasets in your"ibrary?

    $mport mar+et,data,onedata into your "ibrary

    using import s'ript (rint the 'ontents o. the data

    Fow many observations are there in the dataset?

    Fow many variab"es?

    $denti.y non numeri' variab"es

    (rint ;rst ten observations o. the data

    Create a new ;e"d genera"N0uestions6 $. wesubtra't numN'ustomN0uestions .romnumN.ormN;e"ds8 we get genera"N0uestions

    V

    enkata

    Reddy

    -onasani

    =

    Creating new variab"e -

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    68/121

    Creating new variab"e -using i. then e"seCreating a new variab"e using i. then e"se

    datadatalib.market_one_1;

    setdatalib.market_one;

    i-bud&et = 3000thenbud&et_ind=/lo'/;

    elsei-bud&et = 100000thenbud&et_ind=/hi&h/;elsebud&et_ind=/medium/;

    run;

    V

    enkata

    Reddy

    -onasani

    >

    Lab: Creating a variab"e-

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    69/121

    Lab: Creating a variab"e-using i. then e"se Create a new variab"e assetNind6

    $. the number o. assets are greater than Bero thenassetNind takes the va"ue yes otherwise +

    See pro' 'ontents

    (rint ;rst ten observations Create rea'hNind whi'h takes va"ues 18 and #

    when rea'h is "ess than ##8 ## to and = to16

    (rint ;rst ten observationsV

    enkata

    Reddy

    -onasani

    @

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    70/121

    !rop and keep variab"es

    What i. $m not interested in a"" the ;e"ds? Creating a new data set with "ess number o.

    ;e"ds6

    sing drop statementdatadatalib.market_one_2;

    set datalib.market_one (drop=name start_date end_date+ ;

    run;

    sing eep statementdatadatalib.market_one_$;

    set datalib.market_one (keep=id name bud&et+ ;

    run;

    V

    enkata

    Reddy

    -onasani

    =

    Lab: !rop and keep

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    71/121

    Lab: !rop and keepvariab"es $mport marketNdk data See the 'ontents

    Var18 var8 var# are o. no use .or the ana"ysis

    Create a new data by dropping the unne'essary

    variab"es by using drop statement Create a new data by keeping on"y ne'essary

    variab"es by using keep statement

    V

    enkata

    Reddy

    -onasani

    =1

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    72/121

    Sub setting the data

    Sometimes we need a subset o. the data .or.urther ana"ysis

    datadatalib.market_one_!;

    setdatalib.market_one;'hereertical=/echnolo&y/;

    run;

    or

    datadatalib.market_one_!;

    setdatalib.market_one;

    i-ertical=/echnolo&y/;

    run;

    V

    enkata

    Reddy

    -onasani

    =

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    73/121

    Lab Sub-setting the data

    Create a data set named DgoodNrea'hN'ampE'ontains a"" the 'amps where rea'h is more than *per'ent

    Create using where statement

    Create the same using i. statement $s there any diXeren'e between where and i.?

    (rint a subset o. data: 4ry to print the data where rea'h is more than @

    se i. and print again

    i. +4%# observations read .rom the data set !A4AL$&63AR

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    74/121

    3a5or diXeren'esbetween where and i.

    V

    enkata

    Reddy

    -onas

    ani

    =%

    Where statement IF statement

    Selects observations before they arebrought into the program data vector,making it a more efficientprogramming technique.

    Works on observations after they areread into the program data vector.

    Cannot be executed conditionally aspart of an I statement

    !he sub setting I statement can

    be executed conditionally

    Can be used in S"S procedures Cannot be used in S"S procedures tosubset observations for bro#sing orediting.

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    75/121

    SAS .un'tions - +umeri'

    Sum8 min8 ma,8 avg .un'tions

    data334I5.378_t'o_1;

    set334I5.378_t'o;

    sum_t'o=:um(ebinar

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    76/121

    Lab: )un'tions

    16 4here is some error in the number o. assets;e"d6

    6 Create a variab"e numNasset to veri.y number o.assets .ormu"a6 +umber o. assents is nothing

    but the sum o.WhiteN(aper8Webinar8So.twareN!own"oad8)reeNXer8LiveN

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    77/121

    String .un'tions

    datadatalib.market_one_";

    setdatalib.market_one;

    ertical_ind=substr(ertical

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    78/121

    Lab: String .un'tions

    Create nameNnew by taking ;rst 'hara'ters o.the name variab"e

    Create a new variab"e by 'onverting the name o.

    the 'ampaign into upper'ase Guse +C"S-

    function) Create a Zag variab"e that takes va"ue 1 $.

    'ampaign starting month is not e0ua" to 'ampaignending month

    Venkata

    Reddy

    -onas

    ani

    =>

    ! ) i

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    79/121

    !ate )un'tions

    datadatalib.market_one_";

    setdatalib.market_one;

    start_month=month(start_date+;

    start_date1=day(start_date+;

    uration_days=I>C8(/day/

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    80/121

    Lab: !ate .un'tions

    Fow many 'ampaigns started in \anuary? Fow many 'ampaigns started on Saturday or

    Sunday?

    What is the duration o. ea'h 'ampaign? Create

    three variab"es !urationNdays

    !urationNmonths

    !urationNweeks

    Fow many market 'ampaigns run more than

    monthsVenkata

    Reddy

    -onas

    ani

    >

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    81/121

    Step-%: &asi' (ro'eduresand )un'tions

    Venkata

    Reddy

    -onas

    ani

    >1

    C t t

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    82/121

    Contents

    4he (RC step (RC C+4

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    83/121

    Components o. SAS(rograms

    SAS programs are 'onstru'ted .rom two basi' bui"dingb"o'ks:

    16 !A4A steps

    6 (RC steps 4hese two types o. steps8 a"one or 'ombined8 .orm a""

    SAS programs6 2enera""y8 a step ends with a R+ statement or when a

    new !A4A or (RC step begins6

    Venkata

    Reddy

    -onas

    ani

    >#

    (RC t

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    84/121

    (RC step

    &egins with the keyword (RC (re-written routines that enab"e you to ana"yBe

    and pro'ess the data

    Sometimes 'reate SAS data sets that 'ontain the

    resu"ts o. the pro'edure (resent the data in the .orm o. a report

    )or e,amp"e Create a report that "ists the data

    (rodu'e des'riptive statisti's Create a summary report

    (rodu'e p"ots and 'harts

    Run regression ana"ysis

    Venkata

    Reddy

    -onas

    ani

    >%

    ( C t t

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    85/121

    (ro' Contents

    (ro' 'ontents des'ribes the stru'ture o. the SAS data set6 2ives.o""owing in.ormation -

    !ata set "eve" !etai"s o. data "ike +ame8 'reation date8 +umber o. observations

    G weighted and un-weightedH8 +umber o. variab"es8 )i"e siBe anda''ess permissions

    Variab"e "eve" (rovides des'riptive stats a'ross ea'h variab"e su'h as +ame8 4ype

    GChara'ter vs6 +umeri'H8Length8 )ormats8 (osition and Labe"s

    (ro' 'ontents dataM UUdata namePP7 run7

    Useful options :

    Short Outputs the list of variables in a row by row format.

    Code : proc contents data=test short;run;

    Out=filename- Creates a data set wherein each observation is a variable

    from the original data set.

    Code : proc contents data=test out=test2noprint;run;

    Venkata

    Reddy

    -onas

    ani

    >*

    L b ( C t t

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    86/121

    Lab: (ro' Contents

    $mport (ri'eNwebNdata6'sv7 See the datades'ription6pd. ;"e

    (rint the 'ontents

    Are a"" the variab"es in e,pe'ted .ormat?

    (rint on"y ;e"d names o. the datasetproccontentsdata=class1.market_one short;

    run;

    4ake the output o. 'ontents into a sas ;"e8 name it'ontentsNoutproccontentsdata=class1.market_one out=con_out noprint;

    run;Venkata

    Reddy

    -onas

    ani

    >

    ( S t

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    87/121

    (ro' Sort

    (rimari"y used to sort the observation o. yourdata by a 'ertain variab"e or 'o""e'tion o.variab"es6

    Fowever8 it 'an a"so be used to 'reate a new

    data set8 subset your data8 rename8 drop8 orkeep variab"es8 and .ormat or "abe" variab"es6

    procsortdata=class1.market_one out=ne';

    by start_date ;

    run;

    A"most a"ways a good idea to use the 4M option when using pro'sort to do anything e,'ept .or a simp"e sort6 &e'ause (ro' Sortautomati'a""y writes over your data set]

    Venkata

    Reddy

    -onas

    ani

    >=

    L b ( S t

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    88/121

    Lab: (ro' Sort

    Sort marketNone data by budget Sort marketNone data by budget des'ending

    Sort data by date and rea'h

    se marketNone tab"e and 'reate a new tab"e

    'ampanNnames8 sort name in a"phabeti'a"

    Venkata

    Reddy

    -onas

    ani

    >>

    ( S t

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    89/121

    (ro' Sort

    Sorting and removing the dup"i'ates

    procsortdata=class1.market_one out=class1.names_table nodupkey;

    byname ;

    run;

    Sorting and removing the dup"i'ate re'ords

    procsortdata=class1.market_one out=class1.names_table nodup;

    byname ;

    run;Venkata

    Reddy

    -onas

    ani

    >@

    Lab (ro' Sort

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    90/121

    Lab: (ro' Sort

    Sort the dataset by date7 dont overwrite theorigina" data

    Create a new dataset whi'h 'ontains a"" theuni0ue brands on a given dateGA dataset wherethe brand name does not repeat on a given dayH

    Fow many uni0ue produ'ts are there in thedataset? Crate a new data set with this uni0ue "ist

    Venkata

    Reddy

    -onas

    ani

    @

    (ro' S0"

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    91/121

    (ro' S0"

    procsql;

    createtableclass1.market_s*l as

    select?

    -romclass1.arket_t'o

    'herenum_assets0;

    quit;

    [uit instead o. run?Venkata

    Reddy

    -onas

    ani

    @1

    Lab (ro' S0"

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    92/121

    Lab: (ro' S0"

    $mport marketNdataNthree Crate a new tab"e where budget is greater than Bero

    $n marketNone data ;nd the average budgetandaverage rea'h .or ea'h verti'a"

    Create a new tab"e by inner 5oining marketNone8marketNtwo 5oin them on idprocsql;

    createtableclass1.market_one_t'o as

    select?

    -romclass1.arket_one asa [email protected]_t'o asb

    ona.id=b.id;

    quit;

    Create a new tab"e by inner 5oining above tab"e tomarketNthree tab"e8 save the ;na" tab"e asmarketN;na"Ndata

    Venkata

    Reddy

    -onas

    ani

    @

    Lab: (ro' S0"

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    93/121

    Lab: (ro' S0"

    )ind the .re0uen'y o. ea'h brandG'ount number o.times a brand appearsH8a"so average "ist pri'e .orea'h brand6 Save this data as brandNdata

    procsql;

    createtablebrand_data as

    selectbrand< count(ro'id+ as-re*< mean(listprice+ asa&_list_price

    -romclass1.price_data

    &roupby brand;

    quit;

    )or ea'h produ't ;nd the number o. appearan'es8

    average rating and tota" review 'ount8 name thisdata as produ'tNdata

    Venkata

    Reddy

    -onas

    ani

    @#

    (ro' 2p"ot

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    94/121

    (ro' 2p"ot

    S'atter p"ot

    procgplotdata= class1.market_-inal_data;

    plotbud&et_leads?bud&et;

    'herebud&et 100000;

    run;

    Venkata

    Reddy

    -onas

    ani

    @%

    Lab: (ro' 2p"ot

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    95/121

    Lab: (ro' 2p"ot

    $. Average pri'e is "ess8 then .re0uen'y wi"" bemore8 i. pri'e is more then .re0uen'y wi"" be "ess6

    Veri.y the above statement by drawing a s'atterp"ot graph between .re0 and average "ist pri'e inbrandNdata

    Venkata

    Reddy

    -onas

    ani

    @*

    (ro' 2'hart

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    96/121

    (ro' 2'hart

    Verti'a" &ar 'hartprocgchartdata= class1.market_-inal_data;

    barertical , type=sumsumar=total_leads;

    Run;

    Vbar J a,is 'atogiry

    4ype type o. aggregation

    sumvar I a,is variab"e 4he above s'ript shows sum o. "eads .or ea'h verti'a"

    procgchartdata= class1.market_-inal_data;

    barertical , type=meansumar=total_leads;

    Run;

    Venkata

    Reddy

    -onas

    ani

    @

    Lab: (ro' 2'hart

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    97/121

    Lab: (ro' 2'hart

    !raw a verti'a" bar graph whi'h shows a"" thebrands and the average number o. reviewsGseorigina" pri'eNdataH

    !raw a horiBonta" bar graph .or the same

    !raw a bar 'hart .or number o. produ'ts by sitename Iou may want to use 'ount

    4ry .re0 i. it doesnt work

    Venkata

    Reddy

    -onasani

    @=

    (ie 'hart

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    98/121

    (ie 'hart

    PROCGCHART33=class1.price_data;

    Icate&ory;

    RUN;

    Venkata

    Reddy

    -onasani

    @>

    Lab: (ie 'hart

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    99/121

    Lab: (ie 'hart

    4here was a 'omp"aint that one in every .ouritems "isted on the site is out o. sto'k6 $s thattrue? !raw a pie 'hart to veri.y

    !raw a pie whi'h shows the per'entage o.produ'ts with .ree shipping avai"abi"ity nonavai"abi"ity

    Venkata

    Reddy

    -onasani

    @@

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    100/121

    Step-*: Combining

    !atasets in SAS

    Venkata

    Reddy

    -onasani

    1

    Co%bing d"t" set

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    101/121

    Co%bing d"t" set

    Co%bining d"t"sets in " ,A$A step

    oConc"ten"te Append

    SE$

    o*nterle"#eSE$ ? 7@

    o+erge

    +ERE

    +ERE ? 7@ .enkata/eddy0onasani

    (1(

    Conc"ten"tionBAppending

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    102/121

    Conc"ten"tionBAppending

    Si%pl: "ppendingBst"king o the d"t"

    Eg +onth b: %onth d"t" conc"ten"tedto or% :e"r end d"t"

    Conc"ten"ting d"t" ro% #"riouscusto%ers to %"ke " %"ster d"t"set

    .enkata/eddy0onasani

    (1&

    !emo: Appending

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    103/121

    !atasetsdatastore1;

    inputcustomer A;

    cards;

    rB

    rB3rBD

    ;

    datastore2;

    inputcustomer A;cards;

    rB5

    rBE

    rBC

    dataoerall;

    setstore1 store2;run;

    procprintdata=oerall;

    run;

    .enka

    ta/eddy0onasani

    (12

    Lab: Con'atenation

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    104/121

    Lab: Con'atenation

    Create there datasets out o. pri'e web data8 based on brandSamsung8 app"e others

    Crate a new variab"e in app"e dataset8 dis'Npri'eNapp"e whi'his ^ o. a'tua" 'ost

    Con'atenate the three datasets

    Fow many ;e"ds are there in the new dataset? Crate .our datasets out o. te"e'om 'omp"aints data8 based onstatus '"osed8 open8 4emporary C"osed and others

    eep on"y de" number8 'ustomer emai" id and status

    Con'atenate a"" these .our datasets to .orm a newNovera""dataset

    datatech_mark ener_mark;

    setdatalib.market_one;

    i-ertical=/echnolo&y/thenoutputtech_mark ;

    elsei- ertical=/ner&y/thenoutputener_mark;

    run;

    .enka

    ta/eddy0onasani

    (13

    *nterle"#e

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    105/121

    *nterle"#e

    Appending si%pl: "ppends We %": w"nt to %"int"in the order r"ther th"n Dust "ppending

    *nterle"#e Ordered st"cking

    .enka

    ta/eddy0onasani

    (14

    !emo: $nter"eave

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    106/121

    !emo: $nter"eave

    datastore1;inputcustomer A;

    cards;

    rB

    rB3

    rBD;

    datastore2;

    inputcustomer A;

    cards;rB5

    rBE

    rBC

    ;

    dataoerall;

    setstore1 store2;

    by name;run;

    procprintdata=oerall;run;

    .enka

    ta/eddy0onasani

    (15

    !emo: $nter"eave

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    107/121

    !emo: $nter"eave

    datastore1;inputcustomer A;

    cards;

    rB

    rB3

    rBD;

    datastore2;

    inputcustomer A;

    cards;rB5

    rBE

    rBC

    ;

    dataoerall;

    setstore1 store2;

    run;

    procprintdata=oerall;

    run;

    procsortdata=store1;

    by customer;

    run;

    procsortdata=store2;

    by customer;

    run;

    .enka

    ta/eddy0onasani

    (16

    LA& $nter "eaving !ataset

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    108/121

    LA& $nter "eaving !ataset

    Crate .our datasets out o. te"e'om 'omp"aints data8based on status '"osed8 open8 4emporary C"osed andothers

    eep on"y de" number8 'ustomer emai" id and status6

    $nter"eave by a"" these .our datasets by de" number to

    .orm a newNovera"" dataset Create there datasets out o. pri'e web data8 based on

    brand Samsung8 app"e others

    Crate a new variab"e in app"e dataset8 dis'Npri'eNapp"ewhi'h is ^ o. a'tua" 'ost

    Con'atenate the three datasets based on date

    Fow many ;e"ds are there in the new dataset?.enka

    ta/eddy0onasani

    (17

    )rom set to 3erge

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    109/121

    )rom set to 3erge

    3erging is simi"ar to 5oins but not e,a't"y same as 5oins ptions need to be used in proper order to .orm the desired

    datasetdatastudents1;

    inputname A maths;cards;

    7am #%

    7obert 90

    7aheem %0

    Fopi #"3nil 60

    ;

    datastudents2;

    inputname A en&lish;

    cards;

    7am ""7obert #0

    7aheem 60

    Gred #"

    3lex "0

    ;proc

    sort

    data=students1; byname;run

    ;procsortdata=students2; byname; run;

    datat'o_sub;

    setstudents1 students2;byname;

    run;

    roc print data=t'o_sub; run;

    .e$lace et (y /erge

    .enka

    ta/eddy0onasani

    (18

    +"tched +erging

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    110/121

    +"tched +erging

    datat'o_sub;

    setstudents1 students2;byname;

    run;

    datat'o_sub;

    er&e students1 students2;

    byname;run;

    Obs name maths english

    1 Alex . 50

    2 Anil 60 .

    3 Fred . 75

    4 Gopi 75 .

    5 Raheem 80 60

    6 Ram 78 55

    7 Robert 0 70

    Obs name maths english

    1 Alex . 50

    2 Anil 60 .

    3 Fred . 75

    4 Gopi 75 .

    5 Raheem 80 .

    6 Raheem . 60

    7 Ram 78 .

    8 Ram . 55

    Robert 0 .

    10 Robert . 70

    .enka

    ta/eddy0onasani

    ((1

    3erging

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    111/121

    3erging

    3erge "ooks .or the mat'hing variab"es and 'reated a'onso"idated merged dataset

    !A4A output-SAS-data-set7 3

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    112/121

    LA&: 3at'hed 3erging

    $mport rders data spot data into two diXerent datasets .rom 4V 'ommer'ia" data

    Sort both data sets based on iSC$A!-i!

    3erge orders and s"ots based on iSC$A!-i!

    Fow many observations are there in the 'onso"idateddataset

    datat'o_sub;

    er&e students1 students2;

    byname;

    run;

    .enka

    ta/eddy0onasani

    ((&

    3erge With Conditions

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    113/121

    3erge With Conditions

    What i. we want 'omp"ete detai"s .rom dataset-1 and mat'hing detai"s .ormdataset-1

    3arks o. on"y students .rom data set1 and .et'h their

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    114/121

    'onditiondatat'osub_student1;

    mer&estudents1(in=a+ students2(in=b+;

    byname;

    i-a;

    run;

    datat'osub_student2;

    mer&estudents1(in=a+ students2(in=b+;

    byname;

    i-b;

    run;

    procprintdata= t'osub_student1;run;

    procprintdata= t'osub_student2; run;

    .enka

    ta/eddy0onasani

    ((3

    3erge Condition

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    115/121

    Statementsust "e in 1st dataset#

    i$in1# % &a'e as( i$in1 ) 1#

    ust "e in 2nd dataset#

    i$in2#

    ust "e in "oth datasets#

    i$in1 and in2#

    .enka

    ta/eddy0onasani

    ((4

    3erge Condition

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    116/121

    Statements

    in( $ (

    in& $ 1

    9"!"S-! ( 9"!"S-! &

    in( $ 1

    in& $ (

    in( $ (

    in& $ (

    .enka

    ta/eddy0onasani

    ((5

    LA&: 3erge withdi i

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    117/121

    Condition 3erge the data sets orders and spot data Create a new data set with a"" orders data a"ong

    with mat'hing spot data ;e"ds

    Create a new data set with a"" spot data a"ongwith mat'hing orders data ;e"ds

    ((6

    .enka

    ta/eddy0onasani

    datat'osub_student1;

    mer&estudents1(in=a+ students2(in=b+;

    byname;i-a;

    run;b

    LA&: 3erge withC di i

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    118/121

    Condition Sort both bi"" and 'omp"aints data on de"Nno6

    Remove dup"i'ates using nodupkey on de"Nno

    Atta'h 'omp"aint detai"s o. the 'ustomers to thebi""ing data8 a"" 'ustomers might not have

    'omp"aints Atta'h bi""ing detai"s to 'omp"aints data8 i.avai"ab"e

    Create a data set and print a"" the 'ustomerswhose bi""ing and 'omp"aints detai"s are avai"ab"edatat'osub_student1;

    mer&estudents1(in=a+ students2(in=b+;

    byname;

    i-a;

    run;

    .enka

    ta/eddy0onasani

    ((7

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    119/121

    +e,t

    Steps

    Venkata

    Reddy

    -ona

    sani

    11@

    What ne,t??

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    120/121

    What ne,t??

    Venkata

    Reddy

    -ona

    sani

    1

    SAS &asi's

    LearnAdvan'ed

    SASprogramingte'hni0ues

    SAS!eve"oper

    Re.: 4heLitt"e SAS

    &ook

    Learn !ata

    Ana"yti's

    !ataAna"yst

    Re.:(ra'ti'a"&usinessAna"yti'susing SAS

  • 7/21/2019 Stepbysteplearningsasbasicsv1 150218054117 Conversion Gate02

    121/121

    4hank you

    Venkata

    Reddy

    -ona

    sani

    11