1. Base Programming - Le site web des Mathématiques du...

37
1. Base Programming GIORGIO RUSSOLILLO - Cours de prépara+on à la cer+fica+on SAS «Base Programming» 10

Transcript of 1. Base Programming - Le site web des Mathématiques du...

Page 1: 1. Base Programming - Le site web des Mathématiques du …maths.cnam.fr/IMG/pdf/SAS_01_cle49c4eb.pdf · 1. Base Programming GIORGIO RUSSOLILLO - Cours de préparaon à la cer+ficaon

1.BaseProgramming

GIORGIORUSSOLILLO-Coursdeprépara+onàlacer+fica+onSAS«BaseProgramming» 10

Page 2: 1. Base Programming - Le site web des Mathématiques du …maths.cnam.fr/IMG/pdf/SAS_01_cle49c4eb.pdf · 1. Base Programming GIORGIO RUSSOLILLO - Cours de préparaon à la cer+ficaon

WhatisSAS

•  Highlyflexibleandintegratedsokwareenvironment;youcanuseSASfor:

GIORGIORUSSOLILLO-Coursdeprépara+onàlacer+fica+onSAS«BaseProgramming» 11

Page 3: 1. Base Programming - Le site web des Mathématiques du …maths.cnam.fr/IMG/pdf/SAS_01_cle49c4eb.pdf · 1. Base Programming GIORGIO RUSSOLILLO - Cours de préparaon à la cer+ficaon

BaseSAS

Thefounda+onofSASsokwareiscalledBaseSAS.

GIORGIORUSSOLILLO-Coursdeprépara+onàlacer+fica+onSAS«BaseProgramming» 12

Page 4: 1. Base Programming - Le site web des Mathématiques du …maths.cnam.fr/IMG/pdf/SAS_01_cle49c4eb.pdf · 1. Base Programming GIORGIO RUSSOLILLO - Cours de préparaon à la cer+ficaon

ThiscourseassumesthatyouarerunningBaseSASsokwareinthewindowingenvironment

WhichprogrammingworkspaceamIusing?•  Help->About

GIORGIORUSSOLILLO-Coursdeprépara+onàlacer+fica+onSAS«BaseProgramming» 13

Page 5: 1. Base Programming - Le site web des Mathématiques du …maths.cnam.fr/IMG/pdf/SAS_01_cle49c4eb.pdf · 1. Base Programming GIORGIO RUSSOLILLO - Cours de préparaon à la cer+ficaon

Setupprac+cedata

TocreateapermanentSASlibrarynamedsasuser:

•  Help->LearningSASprogramming->OK

GIORGIORUSSOLILLO-Coursdeprépara+onàlacer+fica+onSAS«BaseProgramming» 14

Page 6: 1. Base Programming - Le site web des Mathématiques du …maths.cnam.fr/IMG/pdf/SAS_01_cle49c4eb.pdf · 1. Base Programming GIORGIO RUSSOLILLO - Cours de préparaon à la cer+ficaon

SASprogram

GIORGIORUSSOLILLO-Coursdeprépara+onàlacer+fica+onSAS«BaseProgramming» 15

ASASprogramisadatafilethatisformabedinawaythatSAScanunderstand.Itcanconsistofoneormoresteps:aDATAstep,aPROCsteporanycombina1onofthetwo

Page 7: 1. Base Programming - Le site web des Mathématiques du …maths.cnam.fr/IMG/pdf/SAS_01_cle49c4eb.pdf · 1. Base Programming GIORGIO RUSSOLILLO - Cours de préparaon à la cer+ficaon

DATAstep

YouuseaDATAstepto:-  PutyourdatainaSASdataset-  Computevalues-  Checkforandcorrecterrorsinyourdata-  ProducenewSASdatasetsbysubsepng,

supersepng,mergingandupda+ngexis+ngdata

WithaDATAstepyoucancreateormodifydatasets:

GIORGIORUSSOLILLO-Coursdeprépara+onàlacer+fica+onSAS«BaseProgramming» 16

Page 8: 1. Base Programming - Le site web des Mathématiques du …maths.cnam.fr/IMG/pdf/SAS_01_cle49c4eb.pdf · 1. Base Programming GIORGIO RUSSOLILLO - Cours de préparaon à la cer+ficaon

PROCStepInvokepre-wribenrou+nesthatenableyoutoanalyzeandprocessthedatainaSASdataset

YoucanusePROCstepsto:-  Createareportthatliststhedata-  Producedecrip+vesta+s+cs-  Createasummaryreport-  Produceplotandchart

GIORGIORUSSOLILLO-Coursdeprépara+onàlacer+fica+onSAS«BaseProgramming» 17

Page 9: 1. Base Programming - Le site web des Mathématiques du …maths.cnam.fr/IMG/pdf/SAS_01_cle49c4eb.pdf · 1. Base Programming GIORGIO RUSSOLILLO - Cours de préparaon à la cer+ficaon

Generallyaprograminvolvesacombina+onofthetwostepslikethis:

GIORGIORUSSOLILLO-Coursdeprépara+onàlacer+fica+onSAS«BaseProgramming» 18

Page 10: 1. Base Programming - Le site web des Mathématiques du …maths.cnam.fr/IMG/pdf/SAS_01_cle49c4eb.pdf · 1. Base Programming GIORGIO RUSSOLILLO - Cours de préparaon à la cer+ficaon

SASStatements

19GIORGIORUSSOLILLO-Coursdeprépara+onàlacer+fica+onSAS«BaseProgramming»

ASASprogramconsistsofstatementsASASstatement:-  UsuallybeginswithaSASkeyword-  Alwaysendswithasemicolon

Page 11: 1. Base Programming - Le site web des Mathématiques du …maths.cnam.fr/IMG/pdf/SAS_01_cle49c4eb.pdf · 1. Base Programming GIORGIO RUSSOLILLO - Cours de préparaon à la cer+ficaon

ASASprogram

GIORGIORUSSOLILLO-Coursdeprépara+onàlacer+fica+onSAS«BaseProgramming» 20

Page 12: 1. Base Programming - Le site web des Mathématiques du …maths.cnam.fr/IMG/pdf/SAS_01_cle49c4eb.pdf · 1. Base Programming GIORGIO RUSSOLILLO - Cours de préparaon à la cer+ficaon

UnderstandingaSASprogram•  Treesteps..

GIORGIORUSSOLILLO-Coursdeprépara+onàlacer+fica+onSAS«BaseProgramming» 21

Page 13: 1. Base Programming - Le site web des Mathématiques du …maths.cnam.fr/IMG/pdf/SAS_01_cle49c4eb.pdf · 1. Base Programming GIORGIO RUSSOLILLO - Cours de préparaon à la cer+ficaon

..13statements..

GIORGIORUSSOLILLO-Coursdeprépara+onàlacer+fica+onSAS«BaseProgramming» 22

Page 14: 1. Base Programming - Le site web des Mathématiques du …maths.cnam.fr/IMG/pdf/SAS_01_cle49c4eb.pdf · 1. Base Programming GIORGIO RUSSOLILLO - Cours de préparaon à la cer+ficaon

..Amongthemtwoglobalstatements:

GIORGIORUSSOLILLO-Coursdeprépara+onàlacer+fica+onSAS«BaseProgramming» 23

-  Globalstatementsareall-alone-statements.-  YoucanuseglobalstatementsanywhereinaSASprogram.-  Globalstatementsarenotexecutable;theytakeeffectassoonasSAScompilesprogramstatements.

Page 15: 1. Base Programming - Le site web des Mathématiques du …maths.cnam.fr/IMG/pdf/SAS_01_cle49c4eb.pdf · 1. Base Programming GIORGIO RUSSOLILLO - Cours de préparaon à la cer+ficaon

SASstatementsarefreeformat

-  Theycanbeginandendanywhereonaline-  Astatementcancon+nueonseverallines-  Severalstatementscanbeonthesameline-  BlanksorspecialcharactersseparatewordsinaSASstatement

GIORGIORUSSOLILLO-Coursdeprépara+onàlacer+fica+onSAS«BaseProgramming» 24

Page 16: 1. Base Programming - Le site web des Mathématiques du …maths.cnam.fr/IMG/pdf/SAS_01_cle49c4eb.pdf · 1. Base Programming GIORGIO RUSSOLILLO - Cours de préparaon à la cer+ficaon

Bounderiesofastep:-  AstepbeginsbyDATAorPROCstatements-  AstependsbyRUNorQUITstatement(althoughtheRUNstatementisnotalways

requiredbetweensteps,usingitcanmaketheSASprogrameasiertoreadanddebug)-  Atthestepboundary,SAS:i)executesanystatementsthathavenotpreviously

executedii)endsthestep

ProcessingaprogramDATAsasuser.admit2;SETsasuser.admit;WHEREage>39;RUN;PROCPRINTDATA=sasuser.admit2;RUN;

StepsaresubmibedinEnhancedEditororinProgramEditorwindows

Whenyousubmitaprogram,SASexecutesitstepbystep.

-  AlogisgeneratedintheLogwindow(forbothPROCandDATAsteps)

-  ReportsaregeneratedinOutput(asalist)andinResultsViewer(inHTML)windows

formostofPROCsteps(excep+ons:copy,sort...).YoucanfindreportsalsoinResultswindow. GIORGIORUSSOLILLO-Coursdeprépara+onàlacer+fica+onSAS«BaseProgramming» 25

Page 17: 1. Base Programming - Le site web des Mathématiques du …maths.cnam.fr/IMG/pdf/SAS_01_cle49c4eb.pdf · 1. Base Programming GIORGIO RUSSOLILLO - Cours de préparaon à la cer+ficaon

ReportWindow

PROCREPORTDATA=sasuser.admitWINDOWS;COLUMNSidnamssexageactlevel;

RUN;

SomeSASprogramopenaninterac+vewindow,suchasaREPORTwindow.Youcanusethiswindowtodirectlymodifydata

GIORGIORUSSOLILLO-Coursdeprépara+onàlacer+fica+onSAS«BaseProgramming» 26

Page 18: 1. Base Programming - Le site web des Mathématiques du …maths.cnam.fr/IMG/pdf/SAS_01_cle49c4eb.pdf · 1. Base Programming GIORGIO RUSSOLILLO - Cours de préparaon à la cer+ficaon

Programmingworkspace:EditorWindows

GIORGIORUSSOLILLO-Coursdeprépara+onàlacer+fica+onSAS«BaseProgramming» 27

Page 19: 1. Base Programming - Le site web des Mathématiques du …maths.cnam.fr/IMG/pdf/SAS_01_cle49c4eb.pdf · 1. Base Programming GIORGIO RUSSOLILLO - Cours de préparaon à la cer+ficaon

Programmingworkspace:EditorWindows

EnhancedEditorFeatures:-  OpeningSASprograms-  Entering,edi+ngandsubmipngSAS

programs-  Usingthecommandlineormenus-  SavingSASprograms-  Clearingcontents

-  ColorCodingandsintaxchecking-  Expandableandcollapsibilesec+ons-  Recordablemacros-  Supportforkeyboardshortcuts-  Mul+-levelundoandredo

ProgramEditorFeatures:-  OpeningSASprograms-  Entering,edi+ngandsubmipngSAS

programs-  Usingthecommandlineormenus-  SavingSASprograms-  Clearingcontents

-  RecallingSubmibedstatements

GIORGIORUSSOLILLO-Coursdeprépara+onàlacer+fica+onSAS«BaseProgramming» 28

Forclearanyofthesewindows,whenthewindowisac+ve:Edit->Clearall

Page 20: 1. Base Programming - Le site web des Mathématiques du …maths.cnam.fr/IMG/pdf/SAS_01_cle49c4eb.pdf · 1. Base Programming GIORGIO RUSSOLILLO - Cours de préparaon à la cer+ficaon

SepngresultformatsTwoformats:Lis+ngandHTML.Differentversions,differentdefault.-  BothHTMLandLISTINGarethedefaultinSAS9.3inWindowsandUNIX-  JustHTMListhedefaultinSAS9.4inWindowsandUNIX

-  Inotherplavorms,youhavejustLISTINGmode,butyoucancreateHTMLoutputusingprogrammingstatements

-  YoucanchoosetoshowtheHTMLoutputinanotherbrowser

Tools->Op+ons->Preferences->Results

GIORGIORUSSOLILLO-Coursdeprépara+onàlacer+fica+onSAS«BaseProgramming» 29

Page 21: 1. Base Programming - Le site web des Mathématiques du …maths.cnam.fr/IMG/pdf/SAS_01_cle49c4eb.pdf · 1. Base Programming GIORGIO RUSSOLILLO - Cours de préparaon à la cer+ficaon

TheLogwindows-  TheLogwindowdisplaysmessagesaboutyourSASsessionandaboutanySAS

programsthatyousubmit.-  Todisplaythiswindow:View->Log-  Toclearthiswindow:Edit->Clearall

GIORGIORUSSOLILLO-Coursdeprépara+onàlacer+fica+onSAS«BaseProgramming» 30

Page 22: 1. Base Programming - Le site web des Mathématiques du …maths.cnam.fr/IMG/pdf/SAS_01_cle49c4eb.pdf · 1. Base Programming GIORGIO RUSSOLILLO - Cours de préparaon à la cer+ficaon

Theoutputwindows-  TheOutputandResultViewerwindowslistoutputfromSASprogramthatyou

submit.-  OutputshowsresultsinLISTINGmode,ResultsViewershowsresultsinHTML

mode-  Bydefaulttheyarebehindtheeditorandthelogwindows.Whenyoucreate

output,theyautoma+callymovetothefrontofyourdisplay(OutputbehindResultViewer).

-  Todisplayoutputwindow:View->Output

-  TheResultswindowlistsandarrangesinatreestructuretheoutput.-  Itallowsbrowsingoutputeasily-  Itallowsviewing,savingandprin+ngindividualitemsofoutput-  ItdislaysseparateiconsforLISTINGandHTMLoutputs-  Todisplaythiswindow:View->ResultsGIORGIORUSSOLILLO-Coursdeprépara+onàlacer+fica+onSAS«BaseProgramming» 31

Page 23: 1. Base Programming - Le site web des Mathématiques du …maths.cnam.fr/IMG/pdf/SAS_01_cle49c4eb.pdf · 1. Base Programming GIORGIO RUSSOLILLO - Cours de préparaon à la cer+ficaon

TheexplorerwindowTheExplorerwindowallowsyouto-  ViewandmanageSASfiles(inthelibraries)butalsonon-SAS(external)files.-  CreatenewlibrariesandSASfiles-  Moving,copinganddele+ngfiles-  Createshortcutstoexternalfiles.-  Todisplaythiswindow:View->Explorer

GIORGIORUSSOLILLO-Coursdeprépara+onàlacer+fica+onSAS«BaseProgramming» 32

Page 24: 1. Base Programming - Le site web des Mathématiques du …maths.cnam.fr/IMG/pdf/SAS_01_cle49c4eb.pdf · 1. Base Programming GIORGIO RUSSOLILLO - Cours de préparaon à la cer+ficaon

SASLibraries-  ASASlibraryisa

collec+onofSASfiles

storedinthesame

directory

-  TemporarySASlibrarieslastonly

forthecurrentsession

-  PermanentSASLibrariesare

availableduringsubsequent

sessions

GIORGIORUSSOLILLO-Coursdeprépara+onàlacer+fica+onSAS«BaseProgramming» 33

Page 25: 1. Base Programming - Le site web des Mathématiques du …maths.cnam.fr/IMG/pdf/SAS_01_cle49c4eb.pdf · 1. Base Programming GIORGIO RUSSOLILLO - Cours de préparaon à la cer+ficaon

ReferringaSASdataset

libref Filename

Theyrefertothesame(temporary)library

Twolevel(dividedbyaperiod)names:

GIORGIORUSSOLILLO-Coursdeprépara+onàlacer+fica+onSAS«BaseProgramming» 34

Page 26: 1. Base Programming - Le site web des Mathématiques du …maths.cnam.fr/IMG/pdf/SAS_01_cle49c4eb.pdf · 1. Base Programming GIORGIO RUSSOLILLO - Cours de préparaon à la cer+ficaon

GIORGIORUSSOLILLO-Coursdeprépara+onàlacer+fica+onSAS«BaseProgramming» 35

Ifyoudon’tspecifyalibrarynamewhenyoucreateafile(oryouspecifythelibrarynameWork),thefileisstoredinthetemporarySASdatalibrary

Page 27: 1. Base Programming - Le site web des Mathématiques du …maths.cnam.fr/IMG/pdf/SAS_01_cle49c4eb.pdf · 1. Base Programming GIORGIO RUSSOLILLO - Cours de préparaon à la cer+ficaon

RulesforSASfilenamesandlibref

Filename-  Canbe1to32characterslong

-  Mustbeginwithaleber(uppercaseorlowercase)oranunderscore

-  Cancon+nuewithanycombina+onofnumbers,lebersorunderscores

Ex:Payroll,LABDATA1995_1997,E+matedTaxPayments3

Libref-  Canbe1to8characterslong

-  Mustbeginwithaleber(uppercaseorlowercase)oranunderscore

-  Cancon+nuewithanycombina+onofnumbers,lebersorunderscores

GIORGIORUSSOLILLO-Coursdeprépara+onàlacer+fica+onSAS«BaseProgramming» 36

Page 28: 1. Base Programming - Le site web des Mathématiques du …maths.cnam.fr/IMG/pdf/SAS_01_cle49c4eb.pdf · 1. Base Programming GIORGIO RUSSOLILLO - Cours de préparaon à la cer+ficaon

SASDatasets

GIORGIORUSSOLILLO-Coursdeprépara+onàlacer+fica+onSAS«BaseProgramming» 37

ASASDatasetisafilethatconsistsoftwoparts:

adescriptorpor0on

and

adatapor0on

Page 29: 1. Base Programming - Le site web des Mathématiques du …maths.cnam.fr/IMG/pdf/SAS_01_cle49c4eb.pdf · 1. Base Programming GIORGIO RUSSOLILLO - Cours de préparaon à la cer+ficaon

Descrip+onpor+onPROCCONTENTSDATA=sasuser.insure;RUN;

-  Nameofthedataset

-  Dateand+methedatasetwascreated

-  Thenumberofobserva+ons

-  Thenumberofvariables

-  Theproper1es(aKributes)ofeachvariable

GIORGIORUSSOLILLO-Coursdeprépara+onàlacer+fica+onSAS«BaseProgramming» 38

Page 30: 1. Base Programming - Le site web des Mathématiques du …maths.cnam.fr/IMG/pdf/SAS_01_cle49c4eb.pdf · 1. Base Programming GIORGIO RUSSOLILLO - Cours de préparaon à la cer+ficaon

VariableAbributes:Name

VariableName,astheFileName:

-  Canbe1to32characterslong

-  Mustbeginwithaleber(uppercaseorlowercase)oranunderscore

-  Cancon+nuewithanycombina+onofnumbers,lebersorunderscores

GIORGIORUSSOLILLO-Coursdeprépara+onàlacer+fica+onSAS«BaseProgramming» 39

Page 31: 1. Base Programming - Le site web des Mathématiques du …maths.cnam.fr/IMG/pdf/SAS_01_cle49c4eb.pdf · 1. Base Programming GIORGIO RUSSOLILLO - Cours de préparaon à la cer+ficaon

VariableAbributes:Type

-  Cancontainanyvalues

-  Ablankrepresentsamissingvalueforcharactervariables

-  Cancontainonlynumericvalues

-  Aperiodrepresentsamissingvaluefornumericvariables

GIORGIORUSSOLILLO-Coursdeprépara+onàlacer+fica+onSAS«BaseProgramming» 40

Page 32: 1. Base Programming - Le site web des Mathématiques du …maths.cnam.fr/IMG/pdf/SAS_01_cle49c4eb.pdf · 1. Base Programming GIORGIO RUSSOLILLO - Cours de préparaon à la cer+ficaon

VariableAbributes:LengthLengthismeasuredinbytes

(1character->1byte)

GIORGIORUSSOLILLO-Coursdeprépara+onàlacer+fica+onSAS«BaseProgramming» 41

Numericvariablesarestoredbydefaultin8bytes

Page 33: 1. Base Programming - Le site web des Mathématiques du …maths.cnam.fr/IMG/pdf/SAS_01_cle49c4eb.pdf · 1. Base Programming GIORGIO RUSSOLILLO - Cours de préparaon à la cer+ficaon

Variableabributes:Format&Informat

FormatindicateshowadatavalueisdisplayedbySASEx:Todisplaythevalue1234as$1,234.00youcanusetheDOLLAR8.2format

InformatindicateshowarawdatavalueisreadbySASinordertobeconvertedinaSASdatavalueEx:$12,345.00containstwospecialcharacters.Youcanuseinformatop+onCOMMA10.forremovingdollarsymbolandcomma,inordertostore12345asanumericvalue

GIORGIORUSSOLILLO-Coursdeprépara+onàlacer+fica+onSAS«BaseProgramming» 42

Page 34: 1. Base Programming - Le site web des Mathématiques du …maths.cnam.fr/IMG/pdf/SAS_01_cle49c4eb.pdf · 1. Base Programming GIORGIO RUSSOLILLO - Cours de préparaon à la cer+ficaon

Variableabributes:Label

Thelabelisadescrip+vetextupto256characterlong

GIORGIORUSSOLILLO-Coursdeprépara+onàlacer+fica+onSAS«BaseProgramming» 43

Page 35: 1. Base Programming - Le site web des Mathématiques du …maths.cnam.fr/IMG/pdf/SAS_01_cle49c4eb.pdf · 1. Base Programming GIORGIO RUSSOLILLO - Cours de préparaon à la cer+ficaon

Datapor+on

PROCPRINTDATA=sasuser.insurenoobs;RUN;

Itisacollec+onofvaluesarrangedinarectangulartable

GIORGIORUSSOLILLO-Coursdeprépara+onàlacer+fica+onSAS«BaseProgramming» 44

Page 36: 1. Base Programming - Le site web des Mathématiques du …maths.cnam.fr/IMG/pdf/SAS_01_cle49c4eb.pdf · 1. Base Programming GIORGIO RUSSOLILLO - Cours de préparaon à la cer+ficaon

FileShortcutsYoucancreateafileshortcuttoanexternalfileandstoreitintheFileShortcutsfolderintheExplorerwindow.-  filerefisanop+onalnamethatisusedtoiden+fyanexternalfileinSAS.-  youcanuseafileshortcuttoopenbrowseandsubmitafile-  Whenyoudeleteafileshortcut,thepointertothefileisdeleted.Howeverthe

files+llexistsinitsphysicalloca+on

GIORGIORUSSOLILLO-Coursdeprépara+onàlacer+fica+onSAS«BaseProgramming» 45

Page 37: 1. Base Programming - Le site web des Mathématiques du …maths.cnam.fr/IMG/pdf/SAS_01_cle49c4eb.pdf · 1. Base Programming GIORGIO RUSSOLILLO - Cours de préparaon à la cer+ficaon

HelpUsingthiswindowisataskorientedhelpreferringtotheac+vewindow.Otherop+onsofthehelpmenu:-  SAShelpandDocumenta+on(completeguidetoSAS)-  Gepngstartedtutorials-  LearningSASprogramming(createdatasetusedintraining)-  SASontheweb(technicalsupport)

GIORGIORUSSOLILLO-Coursdeprépara+onàlacer+fica+onSAS«BaseProgramming» 46