Tips and Techniques for the SAS® Programmer

Tips and Techniques for the SAS® Programmer

ID:39766332

大小:650.39 KB

页数:19页

时间:2019-07-11

上传者:不努力梦想只是梦
Tips and Techniques for the SAS® Programmer_第1页
Tips and Techniques for the SAS® Programmer_第2页
Tips and Techniques for the SAS® Programmer_第3页
Tips and Techniques for the SAS® Programmer_第4页
Tips and Techniques for the SAS® Programmer_第5页
资源描述:

《Tips and Techniques for the SAS® Programmer》由会员上传分享,免费在线阅读,更多相关内容在学术论文-天天文库

SASGlobalForum2011Programming:FoundationsandFundamentalsPaper272-2011TipsandTechniquesfortheSAS®ProgrammerHelenCarey,CareyConsulting,Kaneohe,HIGingerCarey,CareyConsulting,Kaneohe,HIABSTRACTIfyouarenewtoprogrammingorevenareanexperiencedprogrammer,youwillbenefitbylearningtipsandtechniquesthatwillhelpyoubemoreproductive.Thispresentationofferstipsinprogramming,efficiency,workhabits,andwheretofindanswerstoyourSASquestions.Thesetipscomefromourownexperienceandfromlearningfromothersthroughtheirpresentationsandpapers.INTRODUCTIONWhilehelpingmanySASusersatauniversity,wehavefoundthemwritingprogramsthehardway.Iftheyhadonlylearnedaboutdatesorfunctionsorthisorthatprocedureorlearnedhowtousetheavailableresources,theycouldhavesavedthemselvesalotoftimeandfrustration.However,whenusingSASsoftware,youquicklydiscoverthattherearemanywaystoachieveyourresults.AsearchontheinternetforSAStips,SASresourcesorSASefficiencyresultsinthousandsofhits.AlsothereareSASPressbooksthatfocusonSAStips.Ourtipsrangefromsimpletimesaverstoopinionsonhowtogeneratetheresults.Manyofthetipsarebriefwithareferencetoapaperorapageonawebsitewithindepthinformationaboutthetopic.Thetopicisworthpursuingingreaterdetailthancanbegiveninthispaper.TheRecommendedReadingsectionattheendofthispaperlistswheretofindthepapers.®OneofSASInstitute’sregisteredtrademarksisthesloganThePowertoKnow.WearegoingtousethewordPOWERtorevealsomefundamentaltips.Gingerthoughtthatthetitleofthispapershouldhavebeen"TheSASSolution:ThePowerYouDon'tKnowYouHave."Thatsoundslikeafuturepaper.ThesearethetopicsidentifiedbytheacrosticPOWER.P–ProceduresO–OutputW–WorkHabitsE–EfficiencyR–ResourcesThetopicdataisnotpartoftheacrosticPOWER.Becauseeverythingstartswiththedata,thatiswherewewillstart.DATAKnowYourDataNeedingtoknowthedataissomethingthatwelearnedfirst-hand.Wewereanalyzingandreportingondatacollectedfromseniorcitizens.Theanalysisindicatedthatmanywereexercisingmorethan4hoursaday.ThatwasnothowIpicturedretirement.Thedatawassupposedly“clean”anditwas.ByrunningaPROCFREQandPROCUNIVARIATE,wediscoveredmanyretireesenjoyedgardeningfor4to8hoursdaily.Gardeningwasconsideredanexercise.Anothertimewehadtoinformaresearcherthathispublishedresultsonapublicwebsitewereincorrectbecausehedidnotunderstandhowthemissingvalueswerecoded.Therefore,knowyourdata.Checkdatavalues,rangeofvalues,frequenciesofvalues,missingvalues,indexvariableswithuniquevalues,completeandconsistentdates,requiredvariables,andduplicaterecords.ApointandclickwaytocheckyourdataistouseSASEnterpriseGuideandthetaskCharacterizeData.Withawizard,youcaneasilycreatesummaryreport,graphs,frequencyandunivariatestatistics.Fornormallydistributeddata,youcanusePROCSQLtoselectextremevalues.procsql;select*,avg(score)asmean,std(score)assdfrommylib.scoresgroupbygenderhavingabs(mean-score)>2*sd;run;quit;1 SASGlobalForum2011Programming:FoundationsandFundamentalsOnewaytocheckyourdataistousePROCFORMATtodefinevalidgroupsandrunPROCFREQonthosegroups.procformat;valuedosefmt0,.01-2='valid'.='missing'other='invalid';procfreqdata=trial;tablesDosage/missing;formatDosagedosefmt.;run;RonCody'sbookCody’sDataCleaningTechniquesincludesprogramsandmacrosfortypicaldatacleaningtasks.UsePROCDATASETSorPROCSQLwiththeviewSASHELP.VCOLUMNdiscussedbelowtolearnmoreaboutthevariablesandtheirattributes.DataStepIfyouarenotfamiliarwiththedatavector,variableattributes,andhowSASprocessesthedatawhilecreatingaSASdataset,thenreadTheEssenceofDATAStepProgrammingbyArthurLi.Thispaperexplainswhathappens“behindthescenes.”Agood,basicunderstandingofhowSASprocessesandstoresdataisessentialtobeingagoodSASprogrammer.Alongwithdatavalues,eachSASdatasetcontainsmetadataordataaboutthedata.Thisinformation,recordedinthedescriptorportionofthedataset,containsinformationlikethenamesandattributesofallthevariables,thenumberofobservationsinthedataset,andthedateandtimethatthedatasetwascreatedandupdated.PROCDATASETSToviewthedescriptorportion,youcanrightclickonthedatasetintheSASExplorerwindowandselectviewcolumnsorprintitwithPROCDATASETS.TheDETAILSoptionliststhenumberofobservations,thenumberofvariables,andthelabelofthedataset.Thisisalsoawaytofindtyposofthevariablenames.Forexample:procdatasetslibrary=workdetails;contentsdata=highschool;run;®MichaelRaithel’spaperPROCDATASETS;TheSwissArmyKnifeofSAShaseverythingyouwanttoknowaboutPROCDATASETS,apowerfulprocedure.Ifyouarejustchangingtheattributesofthevariables,suchastheirnames,informatsandlabels,thenusePROCDATASETStodotheworkforyou,notthedatastep.UsePROCDATASETSinsteadofthedatasteptoconcatenateSASdatasets.Forexample:procdatasetslibrary=youthlib;appendbase=allyearsdata=year1997;run;ViewTableWindowTheViewTablewindowinaSASsession,isaninteractivewaytoview,enterandeditdata.ItisaccessiblefromtheSASExplorerwindowbyclickingonthedatasetorvieworusingtheviewtable(abbreviatedvt)commandfromthecommandbox.Thecommandboxisbelowthemenubar.OnceyouopentheViewTablewindow,youcanselecttoviewonlyspecificcolumnsbytypingthecolumnscommandfromthecommandbox,suchascolumns'memnamenamelabel'.Thisisthesameasusingthehide/unhideontheDataMenuoftheViewTablewindow.ClosetheViewTablewindowbeforesubmittingtheprogramthatrecreatesaSASdataset.Morethanonce,Ihavenotclosedthewindow,havenotreadthelog,andwonderedwhytheresultsdidnotchange.Thisisanexampleofwhereitisimportanttoreadthelogaftereveryrun.Byreadingthelog,IwouldhavefoundoutthatIcouldnotre-2 SASGlobalForum2011Programming:FoundationsandFundamentalscreatemydatasetbecauseitwasopenintheViewTablewindowand“TheSASSystemstoppedprocessingthisstepbecauseoferrors.”Readingthelogaftereveryrunisagoodpracticetofollow.TheAppendixcontainsinformationaboutopeningaViewTablewindowthewayyouwantit.DictionaryTablesADICTIONARYtableisaread-onlySASviewthatcontainsinformationaboutSASlibraries,SASdatasets,SASmacros,andexternalfilesthatareinuseoravailableinthecurrentSASsession.EachDICTIONARYtablehasanassociatedPROCSQLviewintheSASHELPlibrary.YoucanseetheentirecontentsofaDICTIONARYtablebyopeningitsSASHELPviewintheViewTablewindow.TheseSASviewsnamestartswithV,forexample,VCOLUMNorVMEMBER.SASHELP.VCOLUMNwastheviewthatwewereusingaboveintheViewTableWindowsection.HereisanexampleofaccessingSASHELP.VCOLUMNusingPROCSQL.procsql;Resultsselectmemnameformat=$8.,varnum,nameformat=$15.,labelfromsashelp.vcolumnwherelibname='SASHELP'andmemname='ZIPCODE';run;quit;FunctionsHavefunwithfunctions.Usethemtosaveprogrammingtime,makethecodeeasiertoreadandpossiblyexecutefaster.Therearehundredsoffunctionsincategoriesrangingfromarithmeticfunctionstovariableinformationfunctions.Foranin-depthlookatSASfunctions,readCassidy'spaperBuildingaGoodFoundationwithFunctions.NumerousfunctionsareaddedineveryreleaseofBaseSASsoftware.Reviewthenewfunctionsintheenhancementsdocumentation.Herearesomeexamples.TheIFCorIFNfunctionmaybemoreconvenientthanusinganIF/ELSEstatement.IFCreturnsacharactervalueandIFNreturnsanumericvalue.Forexample,insteadofusingifresults>70thengrade='pass';elsegrade='fail';youcanusethisinstead:Grade=ifc(results>70,'pass','fail');/*storecharactervalue*/Tocheckfornumberofvaluesthataremissing,usetheNMISSfunctionifnmiss(ofq1-q20)>7thendelete;Somefunctionsallowalistofvariablesasarguments.UseofthekeywordOFgivestheusertheflexibilitytoincludevariablelists,arrayelementsandothershortcutsforreferencingvariablenames.Thefollowing4examplesusingtheMEANfunctionarefindingthemeanofthevariablesq1,q2,q3.avg=mean(q1,q2,q3);avg=mean(ofq1q2q3);avg=mean(ofq1-q3);arrayqarray(3)q1-q3;Avg=mean(OFQarray(*));3 SASGlobalForum2011Programming:FoundationsandFundamentalsUsethefactthatthecomparisonequalto(=)operatorreturnseitherthevalue0or1.Thisexamplesumsupthenumberofquestionswiththevalue3.Total=sum(q1=3,q2=3,q3=3,q4=3);The%SYSFUNC,%QSYSFUNCmacrofunctionscanexecutemostSASfunctionsandreturntheresultswithanoptionalformat.HereisanexampletoputthecurrentdateandtimeinadesiredformatbyusingtheDATEandTIMEfunctionsin%SYSFUNC.title"%sysfunc(date(),worddate.)";Results:April7,2011title2"at%sysfunc(time(),time.)";at08:00:00TheIFNandIFCfunctionscanalsobeusedin%SYSFUNC.ThemacrovariablesminAgeandmaxAgearecreatedinthefollowingPROCSQLcodeandthenusedtocreatethefootnotewiththe&SYSFUNCandIFCfunction.Thefootnotewillhavethevalueofeither'AgesOK'or'OutofRange'dependingontherangeofagevalues.IntheSQLcode,themacrovariablesminAgeandMaxAgeareproceedbyacolon(:).procsql;selectmin(age),max(age)into:minAge,:maxAgefromsashelp.class;run;%putMinageis&minAgeMaxageis&maxAge;Footnote1"%sysfunc(ifc(&minAge>11and&maxAge<17,'AgesOK','OutofRange'))";ToreviewthenewandenhancedfunctionsinSAS9.2Basesoftware,seetheWhat'sNewinSAS9.2documentationontheSASSupportwebsite.Therearemorethan100newfunctions,suchasCAT,CATS,CATT,CATX(trimsandconcatenates),PROPCASE(forpropercase),CALLSYMPUTX(trimsblanksbeforeassigningthemacrovalue),MEDIAN(getmedian)andPCTL(getpercentiles),LARGEST,SMALLEST,ZIPCODEandZIPDISTfunctions.AlsoinSAS9.2,youcanwriteyourownfunctionsinC,C++,ortheSASlanguage.SocheckoutWhat'sNewinSAS9.2.SASDataSetOptionsTocreatemultipleSASdatasets,usemultipleOUTPUTstatementsortheWHEREoption.datagoodcheck;settrans;ifamount<0thenoutputcheck;elseoutputgood;run;UsetheWHEREoption:datagood(where=(amt>=0))check(where=(amt<0));settrans;run;TestwithASubsetofYourDataIfthedataareorganizedinsomeorder,takearandomsample.UsetheWHEREoptionwiththeRANUNIfunctiontocreateatestfilewithabout10%ofrecords.TheRANUNIfunctionreturnsarandomvaluefromauniformdistribution.datatestdata;setmylib.proddata;whereranuni(729)<=.10;run;MacroLanguageTheSASmacrolanguageisapowerfultoolthatwritesSASstatements.Itisextremelyusefulforrepetitivetasks.Thebasicsarerelativelyeasytolearnandyoucanreapimmediatebenefits.Togetstartedusingthemacrolanguage,®readthepaperSASMacroProgrammingforBeginnersbySusanSlaughterandLoraDelwiche.GetasoundunderstandingofhowSASworksbeforedelvingintothepowerofthemacrolanguage.Youcanstartsmallwith4 SASGlobalForum2011Programming:FoundationsandFundamentalssimplemacrovariablesubstitutionsandslowlybuildyourmacroskills.WeallknowitisagoodideatodocumentourSAScodewithcomments.Todocumentyourmacrocode,usethemacrocomment(%*…;).Betteryet,usedelimitedcomments(/*…*/).Neithermacrocommentsnordelimitedcomments(/*…*/)arepassedoutofthemacro,whenitisresolved.Thestatementsinthemacroarenotrununtilthemacroiscalled.Youcanusethistoyouradvantagetoskipstatementsthatyounolongerwanttorun.Surroundthecodewith%macroand%mendstatements.SeeourpaperJustSkipIttolearnvariouswaystoskipthecode.Atsomepoint,youwillstartwritingmorecomplexmacrocode.Whenyoustartwritingcomplexmacrocodewith%doloops,%if's,multipleampersands,andcomplicatedquotedstrings,youmightwanttoseethegeneratedSAScodewithoutwadingthroughallthelogcomments.YoucandothisbydirectingthecodethatisgeneratedbythemacrotoaspecifiedfilebyusingtheMFILEandMPRINTsystemoptions.Thesyntaxisasfollows:filenamemprint'c:hipsprogramstestmac.sas';*'pathnameandnameoffile';optionsmprintmfile;%your_macroThefilerefmustbeMPRINT.Thepathnamemustincludethenameoftheexternalfilewherethecodethatisgeneratedbythemacroistobestored.Afterthisprogramfinishesexecuting,youcantakethecodegeneratedandrunittounderstandwhatisactuallyhappeningandfixanyproblems.AnothergoodpaperonmacroswithreferencestootherpapersisDalaneyandCarpenter'spaperMacro:SymbolsofFrustration?%Letushelp!AGuidetoDebuggingMacros.ThebestwaytoendthistopiconthemacrolanguageiswiththisquotefromarespectedSASexpert:TobeacompleteSASprogrammeronehastolearnhowtousemacro,conqueritsweaknessesanddifficulties,notavoidmacroaltogether.–IanWhitlockPROCEDURESDoNotOverCodeDATAstepstypicallycreateormodifySASdatasets,buttheycanalsobeusedtoproducecustom-designedreports.Insteadofbuildingreportsinthedataset,usetheoutputdatasetcapabilitiesofprocedures.Wetookareportwritteninthedatastepthatconsistedofover100pagesofcodeandre-wroteitinonly5pagesusingmacros,PROCTABULATE,PROCSUMMARYanduser-definedformats.Anditwaseasiertoreadandmaintain.InvestigateusingtheUNIVARIATE,FREQ,RANK,SORT,SQL,SUMMARY,TABULATE,REPORTandTRANSPOSEprocedures.ByusingPROCTRANSPOSE,youcanrearrangeaSASdatasetsothatobservationsbecomevariablesandvariablesbecomeobservations.Althoughyoucandothesameprocesswithadatastepthatusesarrayprocessing,PROCTRANSPOSErequiresminimalprogramming.Neverassumeyouknoweverythingaboutaprocedure.Reviewaprocedureacoupleofweeksafteryoufirststartusingittolearnaboutusefulfeaturesandcapabilities.Don'toverlooklearningaboutPROCREPORTandPROCTABULATE.Bothareawesomeandpowerfulprocedures.CheckouttheSASPressbooksonbothproceduresandthenumerousconferencepaperspresentedthroughouttheyears.PROCFREQMostSASprogrammershaveusedtheFREQproceduretoevaluatebasicdataquality.ManyvaluablefeaturesofPROCFREQarenotusedevenbyexperiencedSASusers.Beforeturningtomorecomplexprocedures,checkoutwhatisavailableinPROCFREQ.TheFREQprocedurecannowproducefrequencyplots,cumulativefrequencyplots,deviationplots,oddsratioplots,andkappaplotsbyusingODSGraphics.PROCUNIVARIATEThisexampleisfromtheUNIVARIATEProceduredocumentationofBaseSAS(R)9.2ProceduresGuide:StatisticalProcedures,ThirdEdition.Searchfor"univariateTwo-WayComparativeHistogram"tofindtheexampleontheSASwebsite.5 SASGlobalForum2011Programming:FoundationsandFundamentalsThisexampleshowshoweasyitistographicallycomparedatafrom2suppliersfor2yearsusingPROCUNIVARIATE.procformat;valuemytime1='2002'2='2003';title'ResultsofSupplierTrainingProgram';procunivariatedata=disknoprint;classsupplieryear/keylevel=('suppliera''2003');histogramwidth/intertile=1.0vaxis=0102030ncols=2nrows=2;run;PROCSQLWhenSQLwasfirstintroducedinSAS,mystudentassistantalwaysusedPROCSQL.Ithought“whyisn’theusingPROCSORT,PROCMEANS,andPROCPRINTandmerge(join)thedatasetsinthedatastep.Hmm,hewasabletouseoneproceduretodomanytasks."ItstilltookmeawhiletotaketheplungeandlearnSQL.Afterall,allmyoldtoolsstillworked.Thereisalearningcurve,becauseitisdifferencefromtheSASprocedures.IlearnedaboutCartesianjoinsandhownottocreatethousandsandthousandsofunwantedrecords.Ilearnedtotestjoinsonsubsetsofmytables.IlearnedtoincludecommastoseparatethevariablesintheSQLstatement.Today,itisthefirsttoolIreachfor,insteadofthepreviouslymentionedprocedures.EasysolutionstocomplextasksareavailablewithPROCSQL.IfyouarenotusingPROCSQL,considerthesereasonsforlearningit:PROCSQLiseasyandefficienttouseforsummarizingdataandremergingthesummarizeddatawiththeoriginaldata.PROCSQLisanaturalforcomplexjoins(merges)andhastheabilitytoqueryupto32tables(datasets)simultaneously.SQLisastandardized,widelyusedlanguageindataprocessing.ByknowingSQL,youaremoremarketableandyouknowacommonlanguagetocommunicatewithyourdataprocessingcolleagues.TheseexamplesshowyouhoweasyitistoproduceresultsinPROCSQL.Getsummarystatisticsbystatusandyear.procsql;selectSex,Age,count(*)asn,avg(Weight)asavgformat=6.2,std(Weight)asstdformat=6.2,min(Weight)asmin,max(Weight)asmaxfromsashelp.classfitgroupbySex,Age;run;ApowerfulfeatureofPROCSQListheabilitytoplacetheresultsoftheselectstatementintoamacrovariable.HereisanexampleofgettingthelistofvariablenamesinthedatasetSASHELP.ZIPCODEandputtingtheminthemacrovariable&myvar.NoticethatintheSQLcodethemacrovariablemyvarsisprecededbyacolon(:).procsqlnoprint;selectnameinto:myvarsResults:MyVars:ZIP,Y,X,ZIP_CLASS,CITY,separatedby','fromsashelp.vcolumnSTATE,STATECODE,STATENAME,wherelibname='sashelp'COUNTY,COUNTYNM,MSA,AREACODE,andmemname='zipcode';AREACODES,TIMEZONE,run;quit;GMTOFFSET,DST,PONAME,ALIAS_CITY%putMyVars:&myvars;6 SASGlobalForum2011Programming:FoundationsandFundamentalsSortingWithoutRegardToCaseInSAS9.2Tosortdataalphabetically,regardlessofcase,useProcSQL.procsql;createtableSortsaleasselect*fromSalesorderbyupcase(Company);quit;BeforeSAS9.2,tosortregardlessofcase,youeitherusedthePROCSQLwiththeupcasefunction,asshownabove,oratwo-stepprocess.Thattwo-stepprocesswastocreateanuppercaseversionofthebyvariableinthedatastepandthensortusingthatnewvariable.There'sasimplersolutionwiththeSORTprocedureinSAS9.2.TheSASUsageNote31369:SortingTextWithoutRegardtoCaseinSAS9.2explainshowtousetheSORTSEQ=LINGUISTICoptionwithPROCSORT.LinguisticCollationistheculturallyexpectedorderingofcharactersinaparticularlanguage.Here'stheexamplefromthatUsageNote.Thelinguisticruletotreatalphabeticcharactersequallyregardlessofcaseisadequateformanyapplications.Checkoutthedocumentationtofindoutwhatoptionstouseforvariouslanguages.procsortdata=maps.namesout=territoriessortseq=linguistic(strength=primary);byTerritoryname;whereTerritorycontains"France";run;procprintdata=territories;varTerritoryName;title1"TerritoriesofFrance";run;SASEnterpriseGuideUseSASEnterpriseGuidetodoyouranalyzes.SASEnterpriseGuideisapowerfuluserinterfacetoSAS.It'seasytouseandready-to-usetoolsandtasksenablesyoutofocusonthetask,notthecode.ItaccessesthepowerofSASwithoutlearningtheSASprogramminglanguage.ItgeneratestheSAScodeandproducestheresultsthroughapoint-and-clickinterface.Itisalsoforprogrammers.InSASEnterpriseGuide,youcanusethecodeeditortocreatenewcodeormodifyexistingSASprograms.Youcanmodifytasksbyinsertingcode.IfinditeasiertocreatemyPROCTABULATEcodebyrunningthesummarytaskinSASEnterpriseGuideandusingthecreatedcodeasastartingpoint.SohowimportantistheSASEnterpriseGuide?HaveyounoticedthatthereisasectionatSASGlobalForumdevotedtoSASEnterpriseGuide.TherearemanypapersfromthisandpreviousGlobalForumsforyoutolearnmore.Alsothereareon-linetutorials,thebookSASforDummiesandthebookTheLittleSASBookforSASEnterpriseGuide.TheSASOnlineResourcesforStatisticsEducationwebsitehasstepswithshortmoviesonhowtoperformbasicstatisticsusingSASEnterpriseGuide.Gotothewebsite,selectwhichversionofSASEnterpriseGuidetoview,selectananalysisfromthelistintheleftframetoopenasimulationwindow.ThereyouwillbeabletoviewthestepsfortheanalysisinSASEnterpriseGuideinabriefmovie.Ifpossible,usethelatestversionofSASEnterpriseGuidebecausetheenhancementsareworthittoupgrade.OUTPUTFocusOnTheResultsFocusontheresultsandontheuseroftheresults.Askyourselfhowcanyoudelivertheinformationinaformthatisbestunderstoodandusedbythedecisionmakers.Datapresentationcomesinmanyforms–summaryreports,detailreports,lists,statisticaltables,exportstoExcelandgraphs.Visualizehowyouwantthedatadisplayed.Lookatexamplesandothercompanyreportsbutthinkabouthowyoucanhelpthereaderofyourreportsbetterunderstandtheinformationdisplayed.Lookatthedeliverymechanismofyourreports.Insteadofaprintedreport,youcouldproducegraphs,putitonthecompanywebsite,putitinaPDForExcelspreadsheetoruseSAStoemailtheresults.Evenconsiderifthereportis7 SASGlobalForum2011Programming:FoundationsandFundamentalsreallyneededorreportingsomeotherresultsmighthelpthedecisionmakingprocess.WiththeOutputDeliverySystem,youhavethemeanstodelivertheresultsinsomanywaysandforms.Understandthedatatodeterminethesizeofyourreportandwhatlabeling,formattingorgroupingisneeded.WhendevelopingyourtableswithPROCTABULATE,firstexploreandunderstandthedatabyrunningprocedureslikeDATASETS,UNIVARIATE,FREQ,andMEANS.Createamock-upofhowyouwantthetablestoappear.Buildthetableswithtestdata,andchecktheresult.Doublecheckthevaluesofsummaryinformationandpercentages.Determinehowyouwanttohandlemissingvalues.Whenyoulikethelayoutandthetestresultsarecorrect,turnyourattentiontomakingthetablelookgood.Usetitles,formats,labels,andoptionstomakeyourreportmorereadableandimpressive.Afterknowinghowyouwanttopresentyourdata,youneedtodecidewhichSASprocedureortechniqueisbesttouse.Takingthetimetochoosethebesttooltousewillsaveyouconsiderabletimeinthelongrunandbemoreefficient.Spendthetimeupfronttosavetimeinthelongrun.UseGraphsEffectivegraphsclarifyandfocusthedata.Ideallytheyprovideinformationquicklyandunambiguously.JustdoaGooglesearchon“saseffectivegraphs”tofindmanySASpapersondesigningeffectivegraphs.Tufte'sbookTheVisualDisplayofQuantitativeInformation,2ndeditionshowshowtodisplaydataforprecise,effectiveandquickanalysis.Itcanbeborrowedfromyourlocallibraryoraddedittoyourowncollection.ProgrammerswithSAS/GraphexperiencewillbeamazedathowsimpleitistocreatecomplexstatisticalgraphswithODSStatisticalGraphics.NewprogrammersmaynotbeamazedbecausetheydonotknowthedrudgeryofwritingSAS/Graphcodetogettheresultsandlayouttheywant.Tolearnmore,seetheSASTALKSWebinarGettingStarted®withODSStatisticalGraphicsinSAS9.2byBobRodriguez.He’sastatistician(fellowoftheAmericanStatisticalAssociation)whogivesanenlighteningtalk.IfyourcompanylicensesSAS/Graph,besuretoviewthisWebinar.Here'sanexample:odsgraphicson;odshtmlstyle=statistical;odsselectparameterestimatesfitplot;procregdata=sashelp.class;modelweight=height;quit;odshtmlclose;odsgraphicsoff;UsefulPrinterSystemOptionsIfyourprintoutintheSASsessionbeginswithpage256,itrevealsthenumberoftimesyourantheprogrambeforeprinting.Resetthebeginningpagenumberbeforeyourfinalrun.Toresetthepagenumber,thecodeis:optionspageno=1;Tosetorientationandpapersize:optionsorientation="landscape";optionsorientation="portrait";optionspapersize="legal";Toremovepagebreaksandputdashes(-)acrossthepage:optionsformdlim="-";Toreinstallpagebreaks(thereisnospacebetweenthequotes):optionsformdlim="";8 SASGlobalForum2011Programming:FoundationsandFundamentalsToleftjustifyoutput:optionsnocenter;BetterTitlesForBYGroupsToputthevariablenamesand/orvaluesinTITLE,use#BYVAR(byvariable)fortheBYvariable'snameand#BYVAL(byvariable)fortheBYvariable'svalue.ThestatementOPTIONSNOBYLINE;eliminatesthedefaultbylines.optionsnobyline;procprintdata=school;title"scoresgrade#byval(grade)";bygrade;pagebygrade;run;FormatsAformattellsSAShowtowritedatavaluesorgroupdatavaluestogetherforanalysis.SAShasalibraryofnumerousbuilt-informatsforcharacter,numeric,anddateandtimevalues.Youcanalsocreateuser-definedformatswithPROCFORMAT.Auser-definedformatcanbeappliedtomanyvariables.Therefore,youdonotneedtocreateidenticaluser-definedformatswithdifferentformatnamesfordifferentvariables.Inthisexample,the$YesNoformatisusedforallthreevariables.procformat;value$YesNo'0'='No''1'='Yes';procfreqdata=mylib.weather;tablessunnycloudyrain;formatsunnycloudyrain$YesNo.;InsteadofusingaseriesofIFstatements,recodeavariableintoanewvariablebyusingauser-definedformatandthePUTfunction.procformat;valueDepartment1,3,5='Admin'2,4='ITS'6,8,9='HR';dataNewdept;lengthDept$5;setEmployee;Dept=put(Deptno,Department.);run;®TolearnaboutformatsseeLund'spaperUsingSASFormats:SoMuchMorethan―M‖=―Male."OutputDeliverySystem(ODS)TheOutputDeliverySystem(ODS)canchangeyourstandarddulllistingstoamazingoutput.ODScontrolsthelookofallprocedureoutput.Eachoutputiscomposedoftwocomponentobjects:adatacomponent,whichcontainsthedatavaluesandatemplatecomponent,whichcontainshowthepieceshouldlook.Theoutputdestinationscanbelisting(thedefault),HTML,outputdatasets,PDF,RT,XML,Excel(viatheExcelXPtagset)andmore.Evenifyoudon'tuseanODSstatement,youareusingtheOutputDeliverySystem.Thedefaultisthestandardlisting.ODSgivesyoumanyfeaturesandcapabilities,suchastrafficlightingillustratedhere.IfyouleaveouttheODSHTMLstatementsinthisexample,youwillgetthestandardlisting.Procformat;value$sexfmt'M'='lightblue''F'='pink';run;9 SASGlobalForum2011Programming:FoundationsandFundamentalsodshtmlfile='printout.html';procprintdata=sashelp.classnoobs;whereAge=15;varNameHeight;varSex/style=[background=$sexfmt.font_weight=bold];run;odshtmlclose;StandardListingHTMLOutputCheckoutLafler'spaperOutputDeliverySystem(ODS)–SimplyTheBasicsandHaworth'spaperODSTips&Tricks.(WUSS2010).LaurenHaworth,CynthiaZender,MicheleBurlewwroteacomprehensiveODSbookcalledOutputDeliverySystem:TheBasicsandBeyond.ItisavailableonAmazonasapaperbackandKindleedition.WORKHABITSAreYouQualified?Thisisacompositeofactualjobdescriptions.ASASProgrammerexhibitscreativityandsystematicworkhabits;professionalbehaviorandworkhabits;well-organized,meticulousworkhabitsandefficientworkhabits.Herearesometipstohelpyoufulfillthosejobrequirements.OrganizationAndProgrammingStyleMostpapersonprogrammingtips,willmentiontheneedforgooddocumentation,programmingguidelines,andorganization.Axelrod'spaperBootCampforProgrammers:StuffYouNeedToKnowThat’sNotInTheManual–BestPracticestoHelpusAchieveReproducibilityisaselectionofconceptsandorganizingprinciplesthatfocusonthese4areas:documentation,processing,programmingguidelines,andfilestorage.ShealsorefersreaderstoaworthwhilearticlebyPhilipBewigentitledHowdoyouknowyourspreadsheetisright?Principles,Techniques,andPracticeofSpreadsheetStyle.Tomanageprojectinformation,weuseMicrosoftOneNote.Thereareothertools,likeEvernotes.EvernotesisfreeandispopularontheIPadandtheInternet.ModularProgrammingModularprogrammingisusedtobreakupalargeprogramintomanageableunits.WedevelopandkeepourcodetododifferenttasksinseparateSASfiles.Thenweusea%INCLUDEstatementtoincludeeachexternalfileintothecurrentprogram.TheSOURCE2optioncausestheinsertedSASstatementstoappearintheSASlog,otherwisethosesourcestatementsdonotappear.Here'sanexampleofmyprogram.BecauseIhavealreadycreatedthedatasetandcheckedthedata,Iplacedtheasteriskinfrontofthefirsttwo%INCLUDEstatementstoturnthemintocommentssotheyarenotexecuted./*MasterprogramforHighSchoolanalysis*/*%include'C:HIPSprogramsreaddata.sas';*%include'C:HIPSprogramsCheckdata.sas';title"HIGHSCHOOLSYear2009";procprintdata=mylib.school;run;10 SASGlobalForum2011Programming:FoundationsandFundamentals%include'C:HIPSprogramssummary.sas'/source2;%include'C:HIPSprogramsfinalreport.sas'/source2;IfyoustoreyourSASprogramsinastoragelocationsuchasafolderorPDS,youcanassignthefilereftothatstorageareausingafilenamestatement.Thenyoucanjustreferencethefilerefinthe%INCLUDEstatements.Forexample,youcouldwrite:filenamehipspgm'C:HIPSprograms';%INCLUDEhipspgm(readdata);%INCLUDEhipspgm(checkdata);RecycledCodeTherearehundredsofsampleprogramsformostoftheproceduresandmanyexamplesfoundinSASmanuals.Sampleprogramsmakesiteasyforyoutotryoutnewprocedures,viewhowtowritethecodecorrectly,andseethegeneratedoutput.Thereareseveralsourcesofsamplecodeavailableforyouruse.SamplesandSASNotesisavailableattheSASwebsiteunderthetabKnowledgeBase.YoucanfindSAScodefromvariousSASPressbooksbyselectingthebookunderthetabBookstoreandselectingSAScodeanddataunderMoreaboutthisbookontheleftsideofthescreen.YoucanviewtheSASSampleLibrarywithinSAShelp.ItislocatedunderSASHelpandDocumentation.SelectLearningtoUseSASandSampleSASProgramsundertheContentstab.Write,test,documentandstoreyourownre-useablecode.Keepalogandlibraryofyourcode.Usemacrostorepeatcoderatherthancodingrepeatedly.WhenyourunataskinSASEnterpriseGuide,itgeneratesSAScode.SavethecodegeneratedbySASEnterpriseGuideandreuseit.IlikethedraganddropfeaturesofEnterpriseGuide.IprefertorunmysummariestablesinEnterpriseGuideandcopythecodetoaSASsessionwhereImodifyandtweakitforthefinalresults.KeepAnOpenMindIftheprogramnolongerworks,askyourself,“Whatchanged?”Isitdifferentdata,adifferentday,anaddedimprovementtotheprogram,achangeinthesystemorcomputer.Lookforasimplesolutionfirst.IwillneverforgotoneepisodeatthehelpdeskwhenIaskedthestudent'whatdidyouchange?'Heinsistedthattheprogramusetoworkandhedidn'tchangeathing.AfterIfoundtheerrorinthecode,hereplied"Ididn'tchangeanything,myroommatedid."Sothequestionis"whatchanged?"not"whatdidyouchange?"Lookatstatementsandtechniqueswithanopenmind.Beopentonewinformationandanewperspectiveandnotlimityourselftothesameoldways.EvenconsiderwhetherusingSASisthebestchoice.Thefollowingistwowaysofsolvingthesameproblem.The"oneway"wastheprogramthatwasquicklywrittenwithoutforethought.The"simplerway"wastheprogramthatresultedaftersomethoughtandadesiretokeepitsimple.Thetaskistogetfrequenciesofzipcodeareasdefinedbythefirst3digits.Oneway:datatemp;setAccounts;Zip3=substr(Zipcode,1,3);run;procfreqdata=Temp;tablesZip3;run;Simplerway:procfreqdata=Accounts;tablesZipcode;formatZipcode$3.;run;11 SASGlobalForum2011Programming:FoundationsandFundamentalsEnhancedEditorThismaynotseemlikeanefficiencyhintbutitisatimesaverwhenyouarerunninginaninteractiveSASsessionandhavemismatchedorunbalancedquotes.Submitthiscodetofixunmatchedcommenttags,unmatchedquotationmarks,andmissingsemicolons.*';*";*/;ColorcodeyourSASstatements.Isetthebackgroundcolorofmycommentstobeyellowtomakeiteasiertoseeintheprogram.Learntouseshortcutkeys.ChangelinesofcodetoacommentbyselectingthetextandpressingtheCtrl+/keys.Removethe/**/tagsbypressingtheCtrl+Shift+/keys.Useabbreviationstosavetimetyping.Doingthe®simplethingsmentionedherecanreapbenefits.AcomprehensivepapertolearnmoreisHarkins'paperSASEnhancedEditor:EfficientTechniques.WehavebeenusingUltraedit,apowerfultexteditor,foryearsandevenpurchasedalifetimelicense.ManyofthefeaturesthatwereonlyinUltraeditarenowintheSASEnhancedEditor.However,thingslikesearchingfortextinallthefilesinadirectoryorsub-directory,usingregularexpressionsforthesearch,easeofworkingwithtextincolumnsandotherfeaturesstillmakeitworthwhileforus.Sobeonthelookoutforothertoolsandsoftwarethatwillmakeyourworkgosmoother.Finally,considerusingSASEnterpriseGuideasyoureverydaySASeditor.BreakTimeTakecareofyourself.Whenyourbrainistired,itdoesn'tworkwell.Takebreaks,stretch,restyoureyesbyplacingyourpalmsoverthemforafewminutesandstandupandwalkaround.Manywebsitespraisetheadvantagesofastandupdeskonyourhealthandweight.Othersrecommendsittingonanexerciseball.TherearemanyergonomictipsontheInternettohelpyoubemorecomfortableandproductivewhileworkinglonghoursonyourcomputer.LearnnewthingsoutsideofSASprogramming.Youdon'thavetogofar–justaclickaway.WatchonlinevideosfromafrontrowseatandorjogalongwithalecturedownloadedtoyourIPod.Dosomeheavyviewingandlisteningbyvisitingthefreeonlineacademiccourses.Somerecommendedsitesare:OpenCourseWare(ocwconsortium.org),KhanAcademy(khanacademy.org),ITunesU(apple.com/education/itunes-u)andTED(ted.com).Thesearejustastart.OneofmyfavoriteTEDtalksisJillBolteTaylor'sStrokeofInsight.Learningtakestimebutisworththeeffortintheknowledgegainedandgenerationofnewideas.EFFICIENCYWhatMattersMost?Inprogramming,tobeefficientyouwillwanttomakegoodandoptimaluseofyourresources.Firstask“whatmattersmost?”Isitcomputertime,memory,diskstorage,computermemory,yourtimenow,oryourtimeinmaintainingtheprogram?Lookatthetradeoffs.Decidewhichresourcestooptimizeandwhichonesyoucanaffordtouselessefficiently.Ifyouorsomeoneelseneedstomaintainthecode,writethecodeusinggoodprogrammingstyleandorganizationskills.ThinkThinkingandplanningbeforeprogrammingisoneofthebesttipsonefficiency.MarjeFechtinherpaperTHINKBeforeYouType…BestPracticesLearnedtheHardWaygivesbestpracticestominimizeeffortandmaximizeresults.IstillhavemyIBMdeskplacardthatsays“Think."KeepItSimpleKeepitsimple,easyandefficient.Useproceduresinsteadofdatasteps.Avoidunnecessarydatasteps.Forexample,permanentlysaveonlythefinaldataset.Usetemporarydatasetstostoreintermediateresults.Insteadofthis:Usethis:dataMylib.New;dataNew;setMylib.SeptMylib.Oct;setMylib.SeptMylib.Oct;programmingstatementsprogrammingstatementsrun;run;dataMylib.District;dataMylib.District;setMylib.AllMylib.New;setMylib.AllNew;programmingstatementsprogrammingstatementsrun;run;12 SASGlobalForum2011Programming:FoundationsandFundamentalsSaveDiskSpaceSavediskspaceandmakeyourdatasetseasiertounderstandbyinputtingonlythedatayouneed.Dropvariablesyounolongerneed.DATAmylib.yearly(DROP=Rain1-Rain12);SETOld(DROP=Snow1-Snow12);Total=SUM(ofRain1-Rain12);programmingstatementsRUN;DropDOloopindexingvariables.dataMylib.NewCost(DROP=i);setMylib.Cost;arrayAmt(100)Amt1-Amt100;doi=1TO100;Amt(i)=MAX(0,Amt(i));end;run;Storenumericcategoricaldataincharactervariablestosavespace.lengthquest1-quest40$1;Supposeyouhada40questionsurveywith500respondentsandcategoricalresponsesfrom1to9.Itwouldtake20,000bytestostoreitas1character(40x500=20,000)versusstoringitasanumericoflength8(160,000bytes).ThedefaultlengthofnumericvariablesinSASdatasetsis8bytes.Tosavespace,storeintegernumericvariablesinalengthlessthan8,ifyoucan,byusingtheLENGTHstatementforintegervariables.Forexample,dummyvariablesthatwouldhaveonlyavalueof0or1isagoodcandidateforhavingalengthof3.UsetheLENGTHstatementonlyforvariableswhosevaluesarealwaysintegers.Non-integernumbersloseprecisioniftheyaretruncated.lengthIds1-s54Income8default=3;Becarefulwhenchoosingthelength,becausethelargestintegerrepresentedvariesfromonehostsystemtoanother.Thelargestintegernumberthatyoucanstoreunderz/OSwithalengthof3bytesis65,536,onUnixandWindowsitis8,192.SeetheSASCompanionsforaspecifichostsystemformoreinformation.UseFunctionsForDataConversionUsetheINPUTfunctionforcharacter-to-numericconversionandthePUTfunctionfornumeric-to-character.ThevalueofCharAmtinthefollowingexampleisthecharacterstring$1000.99.Amount=1000.99;CharAmt=put(Amount,dollar10.2);Inversion9,dataconversioncanalsobedoneusingtheVVALUEfunction.Itreturnsacharacterstring.Thereisonlyoneargumentanditisthevariablenamewhosevalueistobeconverted.Itusestheformatassociatedwiththevariable.Also,theformatcanbeassignedintheprogramasshowinthecodebelow.formatAmountdollar10.2;CharAmt=(Amount);ThemoreinterestingfunctionistheVVALUEXfunction.ThisallowsyoutousethevalueofonevariabletogetthevaluefromadifferentvariableintheDATAstep.Theargumentisacharacterexpressionwhichmustevaluatetothenameofavariable.Thepowercomesfrombeingabletodefineduringexecutingwhichvariableyouwanttouse.ThisexamplereturnstheformattedvalueofthevariableAmount.Thenameofthevariabletouse(Amount)wasassignedduringexecution.Ifthevariable"Amount"doesnotexist,thenyouwillgetanerrormessage.formatAmountDollar10.2;UseThisVar="Amount";CharAmt=vvaluex(UseThisVar);13 SASGlobalForum2011Programming:FoundationsandFundamentalsTheConstantStaysTheSameAssignaconstanttoavariableinaRETAINstatementinsteadofanassignmentstatement.dataSchool;retainTestYear2008District"Honolulu";programmingstatementsrun;NullandVoidUse_NULL_whenyoudonotneedtocreateaSASdataset.data_null_;setCompany;Amount=SUM(OFSold1-Sold31);ifAmount<90thenputProduct=Amount=;run;AvoidInfinityAvoiddivisionbyzerobytestingforit.Thiswillsavecomputertime.ifNumberne0thenAvg=Total/Number;elseAvg=.;SaveTimeSortingUsetheNOEQUALSoptiononPROCSORTtoreducecomputertimeandmemory.BydefaultSORTkeepsthesameorderoftheobservationswithidenticalBYvariablevaluesastheywereintheinputdataset.TheNOEQUALoptiontellsSAStoignoretheorderofobservationswithinBYgroups.procsortdata=Surveynoequals;BYDept;run;ReadMoreAboutIt!TherearemanySASGlobalForum(formerlyknownasSUGI)andregionalconferencepapersonprogrammingefficiencytechniques.ReadVirgile'spaperTheMostImportantEfficiencyTechniquesandBenjamin'spaperLeaveYourBadCodeBehind:50WaystoMakeYourSASCodeExecuteMoreEfficiently.RESOURCESKnowledgeisoftwokinds:weknowasubjectourselves,orweknowwherewecanfindinformationuponit.—SamuelJohnsonInformationaboutSASsoftwarecomesfrommanysourcesandiscontributedbymanypeople,includingprofessionalwriters,SASdevelopers,conferencepresenters,andpeopleaskingandreplyingtoquestionsonthediscussiongroupsSAS-LandSASForums.IfyouonlyuseSASInstitute’sCustomerSupportCenter(support.sas.com),youaremissingawiderangeofresources.Formoreextensiveinformationonresources,checkoutourpaperHowtoFindAnswers:UsingSASResources.14 SASGlobalForum2011Programming:FoundationsandFundamentalsSASInstitute’sCustomerSupportCenterBesidesusingtheSASSystemhelpfromthetoolbar,visitsupport.sas.comforaworldofinformationaboutSASsoftware.Taketimetovisitthemanytopicslistedintheleftnavigationbarontheirstartpage.ThetopicsundertheKnowledgeBaseisagoodplacetostart.HereyouwillfindtheSASmanualsunderDocumentation,technicalpapersunderPapers,andsampleSAScodeunderSamplesandSASNotes.TheFocusAreashasinformativepapersonnewandexistingproducts.SelectBaseSASunderFocusAreasforpapersonODSandtipssheetsonODS,ODSgraphics,andPerlregularexpressions.YouwillwanttoviewtheWebinarSASTalkTipsandTricksforFinding®SASInformationbyReneeHarper,SASOnlineCustomerSupportSpecialist.SheanswersthequestionsabouthowtobestusetheSASsiteforfindinganswersusingthesearchtools.Besidestellingabouthandysearchfeatures,shealsoinformsyouofwaystostayinformedthroughRSSfeedsandwatches.ThiswayyouwillbeoneofthefirstinyourofficetoknowaboutnewfeaturesofSAS.ForalistofSASblogsthatyoumaywanttoreadorwatch,gotoblogs.sas.com.What’sNewinSASisanotherwaytolearnoutaboutthenewfeaturesandprocedures.ItisavailableatKnowledgeBase/Productdocumentationpage.Repole's®paperDon'tBeaSASDinosaur:ModernizingProgramswithBaseSAS9.2Enhancementsisanotherresource.Step-by-StepProgrammingwithBaseSASSoftwareisintheonlinedocumentationontheSASwebsiteandunderSASHelpandDocumentationintheHelpDropdownmenuofyourSASsession.SelecttheContentstaboftheSASdocumentation.ThenselectSASProducts,BaseSAS,andStep-by-StepProgrammingwithBaseSASSoftware.ThisbookisavailableforpurchaseasaSASpressbookandforviewingasaPDF.IthasanextensiveofcoverageofSASprogramming,788pagestobeexact.Itisagoodplacetolearnaboutthedatastep,SASproceduresandtheOutputDeliverySystem.PeoplePowerNoneofusisassmartasallofus.—AnonymousClickonCOMMUNITYintheleftnavigationpaneatsupport.sas.comtofindoutabouteventslikeSASTalks,SASblogs,forumgroups,e-newslettersandmuchmorecontributedbySASemployeesandSASusers.HereyouwillfindlinkstosasCommunity.organdSAS-L.TakealookatwhatpeoplearecontributingthatwillhelpyouinlearningmoreaboutSAS.AttheSAS-LpageofthesasCommunitywebsite,youwillfindlinkstoothercoolwebsites.SASGlobalForumandmostoftheregionalusersgrouphaveapresenceontwitter,Facebook,andothersocialmediasites.AlsochecktheSASvideosbySASemployeesandSASusersatYouTube.SASConferencePapersOnewaytofindSASpapersistodoaGooglesearch.AnotherwayistovisitLexJansen'swebsiteatlexjansen.com,afavoritesiteofmanySASusers.Saveatree.DonotprintouteverySASpaperorarticlethatyoufindthatyoumightwanttoreadoneday.Theyareeasiertofindifyouuseabookmarkingtool,savewebpagesusingInstapaper,orwriteyourownlisttokeeparecordofthepapersyoumightwanttoreadlater.Youcandownloadpaperstostoreonyourcomputerore-reader.TheIPadande-readerscanstoreandreadPDFsandallowmarkuporbookmarks.Withane-readeryoucanevenreadinbed.AgoodreadforentrylevelprogrammersisVarney'spaperMakingtheTransitionfromCollegetoIndustry.15 SASGlobalForum2011Programming:FoundationsandFundamentalsYourOwnLogKeepyourownlogofusefulinformationandwriteinyourSASmanualsyourownnotesandinsights.Documentthosethingsyoumayneedtoknowagain,likewhatdidnotworkandwhatdid.Retrievinginformationfrommemoryisnotalwaysasquickandeasyaswethinkitwillbeatthetime.Findinginformationinanotebookorjournal,whetheronpaperoronthecomputer,iseasierthansearchingforloosepiecesofpaperscatteredabout.CONCLUSION“Youhaveyourway.Ihavemyway.Asfortherightway,thecorrectway,andtheonlyway,itdoesnotexist.‖FriedrichNietzscheManyofthesetipspointedtootherpaperstoread.Ifyouspendthetimetolearnmorefromthosepapers,youwillreapbenefitsinthelongrun.WhenusingSASsoftware,youquicklyfindoutthattherearemanywaystoachieveyourresults.Thereisnotheway.Sousethetipsthatworkforyou.Andmorepowertoyou.REFERENCES®BaseSAS9.2ProceduresGuide:StatisticalProcedures,ThirdEdition,(May2010),497pages,CaryNC,SASPublishingInc.®Carey,HelenandCarey,Ginger(2008)HowtoFindAnswers:UsingSASResources,ProceedingsofWUSS2008,November2008,Availableathttp://www.lexjansen.com/wuss/2008/ess/ess05.pdfCarey,HelenandCarey,Ginger(1997)SASToday!AYearofTerrificTips,Cary,396pages,CaryNC:SASPublishingInc.Carey,HelenandCarey,Ginger(2006)Paper132-31:JustSkipIt,ProceedingsoftheThirty-firstAnnualSASUsersGroupInternationalConference,Cary,NC:SASInstituteInc.Availableathttp://www2.sas.com/proceedings/sugi31/132-31.pdfUsageNote23138:HowcanIremovemacrocodefrommyoriginalprogramandcreateafileofthecodethatisgeneratedbySASsodebuggingthecodeiseasier?,Samples&Notes,SASInstituteInc.,Availableathttp://support.sas.com/kb/23/138.html.UsageNote31369:SortingTextWithoutRegardtoCaseinSAS9.2,Samples&Notes,SASInstituteInc.Availableat:http://support.sas.com/kb/31/369.htmlACKNOWLEDGMENTSWehavelearnedsomuchfromthevolumeofpaperspresentedatbothSASGlobalForum(formallyknownasSUGI)andtheregionalconferences.ItonlytakeswritingapapertofeelespeciallygratefulfortheauthorsthatgavetheirtimetopassontheirexperienceandwisdomtootherSASusers.RECOMMENDEDREADINGDataCody,Ron(2008)Cody'sDataCleaningTechniquesUsingSAS,SecondEdition,272pages,Cary,NC:SASPublishingInc.®Cassidy,Deb(2011)268-2011:BuildingaGoodFoundationwithFunctions,ProceedingsoftheSASGlobalForum2011Conference.Cary,NC:SASInstituteInc.Dalaney,Kevin,andCarpenter,Art(2004)128-29Macro:SymbolsofFrustration?%Letushelp!AGuidetoDebuggingMacros,ProceedingsoftheTwenty-NinthAnnualSASUsersGroupInternationalConference,Cary,NC:SASInstituteInc.Li,Arthur.(2011)269-2011:TheEssenceofDATAStepProgramming,SASInstituteInc.2011.Proceedingsof®theSASGlobalForum2011Conference.Cary,NC:SASInstituteInc.®Raithel,Michael(2011)138-2010:PROCDATASETS;TheSwissArmyKnifeofSASProcedures,Proceedings®oftheSASGlobalForum2011Conference.Cary,NC:SASInstituteInc.16 SASGlobalForum2011Programming:FoundationsandFundamentalsHerbison,Randy(2008)Replacevariablelabelswithvariablenames,SAS-L@LISTSERV.UGA.EDU,Availableathttp://listserv.uga.edu/cgi-bin/wa?A2=ind0803A&L=sas-l&P=R23858UsageNote23138:HowcanIremovemacrocodefrommyoriginalprogramandcreateafileofthecodethatisgeneratedbySASsodebuggingthecodeiseasier?,Samples&Notes,SASInstituteInc.,Availableathttp://support.sas.com/kb/23/138.htmlProcedures®Rodriguez,Bob.SASTALKSWebinarSeries:GettingStartedwithODSStatisticalGraphicsinSAS9.2,SASInstituteInc.SASOnlineResourcesforStatisticsEducation.SASInstituteInc.,Availableat:http://support.sas.com/learn/statlibrary/UsageNote31369:SortingTextWithoutRegardtoCaseinSAS9.2,Samples&Notes,SASInstituteInc.Availableat:http://support.sas.com/kb/31/369.htmlOutputHaworth,Lauren,(2010)ODSTips&Tricks,ProceedingsofWUSS2010,September2010.Haworth,Lauren,Zender,Cynthia,Burlew,Michele.(2009)OutputDeliverySystem:TheBasicsandBeyond,636pages,Cary,NC:SASPublishingInc.®Lafler,Kirk(2011)273-2011OutputDeliverySystem(ODS)–SimplyTheBasics,ProceedingsoftheSASGlobalForum2011Conference.Cary,NC:SASInstituteInc.”®®Lund,Pete(2011)271-2011UsingSASFormats:SoMuchMorethan―M‖=―Male",ProceedingsoftheSASGlobalForum2011Conference.Cary,NC:SASInstituteInc.Tufte,EdwardR.(2001)TheVisualDisplayofQuantitativeInformation,2ndedition,197pages,GraphicsPressWorkHabitsAxelrod,Elizabeth(2010)BootCampforProgrammers:Stuffyouneedtoknowthat’snotinthemanual–Best®PracticestoHelpusAchieveReproducibility.ProceedingsoftheSASGlobalForum2010Conference.Cary,NC:SASInstituteInc.Availableathttp://support.sas.com/resources/papers/proceedings10/148-2010.pdfBewig,Philip.Howdoyouknowyourspreadsheetisright?Principles,Techniques,andPracticeofSpreadsheetStyle,July,2005.Availableathttp://www.eusprig.org/hdykysir.pdfFecht,Marje(2009)133-2009:THINKBeforeYouTypeBestPracticesLearnedtheHardWay,Proceedingsof®theSASGlobalForum2009Conference.Cary,NC:SASInstituteInc.®Harkins,Kathy(2010)SASEnhancedEditor:EfficientTechniques,ProceedingsofNESUG2003,Availableathttp://www.nesug.org/Proceedings/nesug10/ff/ff08.pdfEfficiencyBenjamin.William(2010)FF-08LeaveYourBadCodeBehind:50WaystoMakeYourSASCodeExecuteMoreEfficiently.ProceedingsofSouthCentralUsersGroup.®Raithel,MichaelandRhoads,Mike(2009)041-2009:YouMightBeaSASEnergyHogIf....Proceedingsofthe®SASGlobalForum2009Conference.Cary,NC:SASInstituteInc.®Virgile,Bob(2007)209-2007:TheMostImportantEfficiencyTechniques,ProceedingsoftheSASGlobalForum2007Conference.Cary,NC:SASInstituteInc.Availableathttp://www2.sas.com/proceedings/forum2007/209-2007.pdfResources®Carey,HelenandCarey,Ginger(2008)HowtoFindAnswers:UsingSASResources,ProceedingsofWUSS2008,November2008,availableathttp://www.lexjansen.com/wuss/2008/ess/ess05.pdf®Harper,Renee.SASTALKSWebinarSeries:TipsandTricksforFindingSASInformation,SASInstituteInc.®Repole,Warren(2009)143-2009:Don'tBeaSASDinosaur:ModernizingProgramswithBaseSAS9.2®Enhancements,ProceedingsoftheSASGlobalForum2007Conference.Cary,NC:SASInstituteInc.Availableathttp://support.sas.com/resources/papers/proceedings09/143-2009.pdf17 SASGlobalForum2011Programming:FoundationsandFundamentals®SASInstituteInc.Step-by-StepProgrammingwithBaseSASSoftware.Cary,NC:SASInstituteInc.788pages,2001.Availableathttp://support.sas.com/documentation/cdl/en/basess/58133/PDF/default/basess.pdfVarney,Brian,(2000)220-25:MakingtheTransitionfromCollegetoIndustry,ProceedingsoftheTwenty-fifthAnnualSASUsersGroupInternationalConference,Cary,NC:SASInstituteInc.Availableathttp://www2.sas.com/proceedings/sugi25/25/po/25p220.pdfCONTACTINFORMATIONYourcommentsandquestionsarevaluedandencouraged.HelenCareyGingerCareyCareyConsultingCareyConsulting808.235.4070808.235.4070carey@hawaii.eduginger@hawaii.edu18 SASGlobalForum2011Programming:FoundationsandFundamentalsAPPENDIX:OPENINGTHEVIEWTABLEWINDOWYOURWAYThesetipsonhowtochangethedefaultcolumnheadingsandtoeasilyopenanoften-usedtablewiththeViewTablewindowdonotfallintothecategoryof"FoundationsandFundamentals."However,indevelopinganddebuggingprograms,IwantedaneasierwaytogettheviewthatIwantedofmydatasetintheViewTablewindow.ThesearesomeofthetipsthatIusedtomakethattaskeasier.Ittakessometimetogettheinitialsetupbutitsavestimeinthelongrun.IusetheViewTablewindowofteninaSASsession.Toopenadatasetforviewing,justclickonthedatasetnameintheSASExplorerwindow.Iwantedtohavethecolumnnames,insteadoflabels,asthedefaultcolumnheadings.OtherwiseafteropeningtheViewTablewindow,IwouldneedtoclickontheViewMenuandthenchooseColumnnames.RandyHerbinsonofferedthefollowingsolutioninhistiponSAS-L.Tochangethedefaultactionofthelibrarymember,dothefollowing.1.Themenubariscontextsensitive.Therefore,firstclickintheSASExplorerwindowinyourSASsessiontomakeittheactivewindow.2.SelectToolsOptionsExplorer.fromthemenubar.3.SelecttheMemberstabintheExplorerOptionswindow.4.SelectTableunderthecolumntypeandthenclicktheEditbutton.5.Selecttheaction&OpenandclicktheEditbutton.6.Addcolheading=nameargumenttotheactioncommand.Colheading=labelisthedefault.7.Repeatsteps4to6formembertypeVIEW.NextIwantedtotakeitonestepfurther.BecauseIopenthesametablewiththesamelayoutoverandoveragain,Iusethiscommandinthecommandbox.Thiscommandwillbeavailableinthedropdownboxforsubsequentuse.vtsashelp.carscolheading=namescolumns='makemodelMSRP'Thatworkedsowell,Idecidedtoaddselectingcertainrows.TheWHEREoptionisusedtoselectonlycertainrows(observations).AddingtheWHEREoptionmakesthecommandratherlong.IdecidetoembedtheVTcommandinaDM(displaymanager)statement.TheDMstatementwouldbeastatementinmySASprogram.TheDMstatementsubmitstheVTcommand,whichmustbeenclosedinquotes.Whenyoustarthavingquoteswithinquoteswithinquotes,itgetstricky.Ifyouareinterestedinthistechnique,copyandpastetheexampleandchangewhatisneeded.Whenthedmstatementissubmitted,theViewTablewindowopens.Youwillneedtoclickitstabatthebottomofthescreentoseeit.Whensubmitted,thiscommandopensthesashelp.carstableanddisplaysonlythemake,model,andMSRPvaluesofBMWcars.dm"vtsashelp.carswhere=""make='BMW'""colheading=namescolumns='makemodelMSRP'";HereisanotherexampleofusingtheVTcommandinaDMstatement.Usethemacrovariable&syslasttoopenthemostrecentlycreateddataset.dm"vt&syslastcolheading=names";*;19

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。
大家都在看
近期热门
关闭