2. Referencing Files and Seng Oponsmaths.cnam.fr/IMG/pdf/SAS_02_cle4fc2c1.pdf · 2. Referencing...

17
2. Referencing Files and Sepng Op+ons GIORGIO RUSSOLILLO - Cours de prépara+on à la cer+fica+on SAS «Base Programming» 47

Transcript of 2. Referencing Files and Seng Oponsmaths.cnam.fr/IMG/pdf/SAS_02_cle4fc2c1.pdf · 2. Referencing...

2.ReferencingFilesandSepng

Op+ons

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

DefiningSASlibraries

PAYATTENTION!AlibraryassignedwiththeLIBNAMEstatement,remainsineffectun+lyoumodifyit,cancelit,otyouendyourSASsession

GIORGIORUSSOLILLO-Coursdeprépara1onàlacer+fica+onSAS«BaseProgramming» 48

ToreferenceapermanentSASfileyou:-  Assignaname(libref)totheSASlibraryinwhichthefileisstored-  Usethelibrefasthefirstpartofthefile’stwolevelname(libref.filename)Todefinelibraries,youcanuseaLIBNAMEstatement

LIBNAMENewLib'\\psf\Home\Documents\MySASFiles\9.4';

Librefsyntaxis

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

DefiningSASlibraries

YoucanalsoassignalibraryfromtheSASExplorerwindowusing:-  Tools->NewLibrary-  TheiconNewLibraryonthetoolbar-  Thepop-upmenuintheExplorerwindow

Librariescreatedinthesewayscanbeautoma1callyassignedatstartupbyselec+ngEnableatStartup

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

ReferencingfilesinotherformatsYoucanusetheLIBNAMEstatementtoreferencefilesthatwerecreatedwithothersoUwareproductsSAScanreadorwritethesefilesbyusingtheappropriateengineASASengineisaninternalinstruc1onthatSASusesforwri+ngandreadingfromfilesinaSASlibrarySASsupportread-onlyaccesstoBMDP,OSIRISandSPSSfiles

LIBNAMElibrefengine‘path’;

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

LIBNAMEspssfileSPSS'\\psf\Home\Documents\MySASFiles\ex.por';PROCCONTENTSdata=spssfile._first_;RUN;PROCPRINTdata=spssfile._first_;RUN;

N.B.:Thephysicalnameassociatedwithalibrefisanactualfilename,notaSASlibrary

Seeingthecontentofalibrary

Youcan:-  exploretheExplorerwindows,usingtoolbarsandpop-upmenus

-  writeacommandintheeditor

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

Seeingthecontentofalibrary:PROCCONTENTS

period space

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

-  _ALL_=toseeallthefilesinthelibrary-  NODS=nodetails.Youcanspecifyit

onlywhenyouspecify_ALL_

Seeingthecontentofalibrary:Equivalentoutput

PROCDATASETS;CONTENTSDATA=sasuser._ALL_NODS;

QUIT;

PROCCONTENTSDATA=sasuser._ALL_NODS;RUN;

ProcedureCONTENTS

StatementCONTENTSinProcedureDATASETS

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

Differences:-  ThedefaultfortheDATA=op+on-  Differentstatements(RUNandQUIT,notmandatory)forendingtheprocedure

Seeingthedescrip+vepartofadataset

PROCDATASETS;CONTENTSDATA=sasuser.admit;

QUIT;

PROCCONTENTSDATA=sasuser.empdatavarnum;RUN;

PROCCONTENTSDATA=sasuser.admit;RUN;

Bydefault,PROCCONTENTSandPROCDATASETlistvariablesalphabe1cally.Tolistvariablenamesintheircrea1onorder,youspecifytheVARNUMop+on,e.g.:

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

SpecifyingResultsFormats

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

YoucanusethePreferencewindowtosettheresultformatthatyouprefer.

Toopenthiswindow:Tools->Op+on->Preferences->Result

Sepngsystemop+ons

Youcan:-  usetheglobalstatementOPTIONSintheeditor

-  usethetoolbar:Tools->Op+on->System->….

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

Sepngsystemop+onsusingtheOPTIONSstatement

OPTIONSop<ons;

Youcanchangetheop+onsinyourlis1ngoutputsubmipngtheOPTIONSglobalstatement:Thesepngsremainineffectun1llyoumodifythem,orun1llyouendyourSASsession

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

YoucanplacetheOPTIONSstatementeverywhere;However,it’sgoodprogrammingprac+cetoplaceitoutsideaDATAorPROCstep

SomeOp+ons•  DATE|NODATE:print|donotprintdateand+meinLISTINGoutput•  NUMBER|NONUMBER:print|donotprintpagenumbers

-  Ifop+onNUMBERisused,addingPAGENO=allowsspecifyingthebeginningpagenumber

•  PAGESIZE=:specifieshowmanylineseachpageofoutputcontains•  LINESIZE=:specifiesthewidthofyourprintline•  YEARCUTOFF=:specifieshowtointerprettwo-digityearvalues.Itdoesnot

affect4-digityearvalues.-  DefaultYEARCUTOFF=1926.Thismeansthatvaluesfrom00to25are

interpretedasyearsfrom2000to2025andvaluesfrom26to99areinterpretedasyearsfrom1926to1999

PROCPRINTDATA=sasuser.admit;RUN;OPTIONSnumberpageno=3nodate;PROCPRINTDATA=sasuser.admit;RUN;

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

OPTIONSnonumberpagesize=20date;PROCPRINTDATA=sasuser.admit;RUN;OPTIONSnonumberpagesize=50date;

FIRSTOBS&OBSop+ons

OPTIONSfirstobs=10obs=15;PROCPRINTDATA=sasuser.empdata;RUN;

OPTIONSfirstobs=10obs=15;PROCPRINTDATA=sasuser.empdata (firstobs=10obs=13);RUN;

OPTIONSfirstobs=1obs=MAX;PROCPRINTDATA=sasuser.empdata

(firstobs=10obs=15);RUN;

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

FIRSTOBS=:tostartprocessingataspecificobserva+on(default=1)OBS=:tostopprocessingakeraspecificobserva+on(defaut=MAX)

Ex:Fromnowobserva+onsfrom10to15willbeprintedeach+methatPROCPRINTwillbeused

Ifyouusetheop+onsbetweenparenthesisinthePROCPRINT,theop+onwillworkforanistanceonly:

Theop+onsinthePROCstatementoverridetheop+onsintheOPTIONSstatement

Sepngsystemop+onsusingthetoolbar

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

FurtherOp+ons•  FORMCHAR:specifiestheformapngcharactersforyouroutputdevice,e.g.for

theoutlinesoftables•  FORMDLIM:specifiesacharacterusedtodelimitpagebreaksinSASsystem

output.Usuallythischaracherisnull:anewpagestartswheneverapagebreakoccurs

•  LABEL|NOLABEL:permitsSASprocedurestotemporalyreplacevariablenamesbylabels.IfNOLABEL,thentheLABELOPTIONisignored.Default:LABEL

•  REPLACE|NOREPLACE:specifieswhetherpermanentlystoredSASdatasetscanbereplaced.NOREPLACEpreventsyoutoinadvertentlyreplacingexis+ngSASdatasets.Default:REPLACE

•  SOURCE|NOSOURCE:controlswhetherSASsourcestatementsarewribentotheSASlog.NOSOURCEspecifiesnottowriteSASsourcestatementstotheSASlog.Default:SOURCE

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

Sepngsystemop+onsusingthetoolbar

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

Searchingforanop+on..