Kaz SAS Manual BasicWord格式文档下载.docx
《Kaz SAS Manual BasicWord格式文档下载.docx》由会员分享,可在线阅读,更多相关《Kaz SAS Manual BasicWord格式文档下载.docx(31页珍藏版)》请在冰豆网上搜索。
5.HowdowecreateSASdata?
9
A)CreateaSASdatausingaSASsyntax9
B)CreateSASdataVia.Ms-ExcelSheets10
C)CreateaSASdatasetviaanexternaltextfile11
6.Examplesofdatasteps12
7.Manipulatingvariablesindatasteps13
8.Lotsofmanipulationtechniquestobeusedinadatastep14
9.UsingCharacterFunctionstocreatenewvariables15
10.Application:
HowdowerestrictanalyticalsamplesusingNMISSfunction15
II.Procedures16
11.PROCCONTENTS:
DescriptionofContents16
12.PROCPRINT:
SeeData17
13.PROCSORT:
SortingObservationsbasedonavalueofvariable19
14.PROCMEANS:
GetDescriptiveStatistics(Mean,STD,Min,Max)20
15.PROCFREQ:
GetFrequencies21
16.PROCUNIVARIATE:
Getelaboratestatisticsandaunivariateplot21
17.PROCPLOT:
PlottingTwoVariables21
18.PROCTIMEPLOT:
TimePlot22
19.PROCCORR:
Correlation22
20.PROCREG:
OLSRegression22
21.PROCLOGISTIC:
LogisticRegression23
22.MAKEANASCHIFILE23
III.MoreProcedures24
23.PROCSTANDARD:
StandardizeValues24
24.PROCRANK:
Rankobservations25
25.PROCSQL:
Creatinggroup-levelmeanvariables25
26.PROCIMPORT26
IV.MergingDataSets27
V.MACROs28
27.Mostcommonwayofusingamacro28
28.SimplemacrousingLETstatement28
29.Macrocanbespecifiedfromdata(notdirectlybyyou)28
I.BasicOperations
1.AskquestionstoSASbyemailingsupport@
WhenyouhaveaquestionaboutSAS,youcanemailSASinstitutes’technicalsupportteam.Theaddressissupport@.Atthebeginningofyouremailcontent,youcopytheinformationyougetattheheadofyourlogfile.ThelogfileisafilethatyougetwhenyourunSAS.Itlookslikethis:
NOTE:
Copyright(c)1999-2001bySASInstituteInc.,Cary,NC,USA.
SAS(r)ProprietarySoftwareRelease8.2(TS2M0)
LicensedtoUNIVERSITYOFXXXXX,SiteXXXXX.
ThissessionisexecutingontheWIN_MEplatform.
IdevelopedmySASskillsmostlybycommunicatingwithSAStechteam.
IoftenuseGOOGLEtogetanswerstomyquestions.IthinkSAS’shelpmenuisnotveryeasytounderstandbecausetheydon’talwaysshowyouthebestexamples.
InWindows,youcanactivateSASbygoingtoSTARTALLPROGRAMTheSASSystem.Confirmthatyougetthreewindows.
1.
Clickthismantorunyourprogram.
Editorfile.Thisiswhereyouwriteyoursyntax.
2.Logfile.Thisfileshowsyourerrors.
3.
Clickonthis!
marktocancelwhentheprogramisrunning.
Outputfile.Yougetresultsinthiswindow.
ClickExplorer
tolookatthedatasets.Seenextpageonthis.
Thissyntax(youtypeinintotheeditorfile)getsyouanexampledatatolookat.
dataabcd;
setsashelp.Prdsale;
run;
Youcanlookatthedatasetinthiswayifyoufollowthefourstepsbelow.
Lookcloselyifthereisanyirregularityindata.
Notes:
Ilookatthedatasetstocheckifthereisanythingwrongwithit.Youmustclosethedatasetsbeforeyourunanythingelseifthesyntaxyouwroteaffectsthedataset.
Togettheviewabovewhereyoucanexaminethedata,followthefollowingsteps.
3.Click
Workorotherfolders.
2.Click
Libraries
4.Click
Thedataset.
1.Click
Explorer
4.Assigninglibrarynameandcreatefolders
YouneedalibnamestatementattheheadofyourSASprograms.Withthese,youassignnicknames(libraryname)toindicatefoldersthathostyourSASdatasets.Forexample:
libnamehere"
C:
\TEMP"
;
libnamethere"
\"
Runningabovecreatestwofolders“here”and“there”inthelibrariesintheexplorer’sviewasyouseeinthepicturebelow(Seepreviouspagetoseehowtogettothisview).
ImaginethereisadatasetcalledMYDATAanditisinC:
\TEMP.Youcancreateitinthisway:
datahere.MYDATA;
X=1;
Thissillydatahasoneobservation,whichisXwhosevalueis1.BecauseyoudecidedtocallthatfolderbyanicknameHERE,youwillbereferringtothedatasetas“here.MYDATA.”Forexample,toprintthecontentsofthatdata,youwilldothis:
procprintdata=here.MYDATA;
Toseewhatvariablesareinthedata,dothis:
proccontentsdata=here.MYDATA;
Whatareotherfolders?
SashelphostslotsofdatasetsthatSASinstitutesshipwiththeSASsoftwarefordemonstration’ssake.IhaveneveropenedSasuserorMaps.“Work”hoststemporarydatasetsthatyoucreateasyouprograminSAS.TemporarydatasetsdisappearifyoucloseyourSASprogram.Permanentdatasets,ontheotherhand,arethedatasetsyoucreatetokeepevenafteryouturnquitSAS.Nextpageelaborateeonthesethings.
Herearesomesillyexamplesyntaxtoshowyouwhatthefoldersdoandwhattemporaryandpermanentdatasetsare.
/*libnamestatementsjustneedtooccuratthebeginningofthesyntaxfile*/
\TEMP"
/*thiscreatesadatacalledWallyinWORKfolder*/
dataWally;
x=1;
y=2;
z=3;
Clickonthesefolderstofinddifferent“Wally”datasets.
/*thiscreatesadatacalledABCinHEREfolder*/
datahere.Wally;
x=4;
y=5;
z=6;
/*thiscreatesadatacalledABCinTHEREfolder*/
datathere.Wally;
x=7;
y=8;
z=9;
/*Useprocprinttoseethecontentofthedatasets*/
procprintdata=work.ABC;
procprintdata=here.ABC;
procprintdata=there.ABC;
5.
HowdowecreateSASdata?
A)CreateaSASdatausingaSASsyntax
Ofcourseyoucancreatedatainyoursyntax.
datakaz;
inputID1SEX$4-9height13-15;
cards;
1Male170
2Female165
3Male
4Male168
5Female170
procprint;
B)CreateSASdataVia.Ms-ExcelSheets
Thisusesthefirstrowforvariablenames.Thenusethissyntaxtoimporttheexcelsheet(C:
\mary.xls)asaSASdataset(JOHN):
PROCIMPORTOUT=JOHN
DATAFILE="
\mary.xls"
DBMS=EXCEL2000REPLACE;
RUN;
/*Thisoneignoresvariablenames.Italsospecifiesthesheetfromwhichtotakedata*/
GETNAMES=NO;
SHEET=”Sheet1”;
Besuretoclosetheexcelsheetwhenyourunthesyntaxtoimportit.Otherwise,yougetthiserrormessage:
ERROR:
File_IMEX_.'
Sheet1$'
n.DATAdoesnotexist.
Importunsuccessful.SeeSASLogfordetails.
TheSASSystemstoppedprocessingthisstepbecauseoferrors.
C)CreateaSASdatasetviaanexternaltextfile
Imagineyouhaveatextfile(say,kaz.txt)thatlookslikethisinyourCtempfolder.
Ifyouknowwherethedatapointsareexactlyinthedata,youcanindicatethelocationsinthefollowingway.
infile"
\TEMP\kaz.txt"
;
Ifcharactervariableisjustoneword(e.g.,Male),thenwedon’treallyneedtotellSASaboutexactlocations.SASwillconsidereachblockofwordsornumbersasonevalue.Butyouneedtosay“missover,”soincaseSASwon’tencounteravalue(asinthethirdobservationinthisdataset)atanexpectedplace,itwillconsideritasamissingvalue.Ifacharactervariablecontainsmorethanoneword,thenusethemethodaboveinsteadofbelow.
missover;
inputIDSEX$height;
DataStepsandCreatingNewVariables
6.Examplesofdatasteps
AnySASprogramconsistsoftwoelements.OneisDATASTEPSandtheotherisPROCs(suchasprocprintorprocmeans).Idiscussdatastepsinthischapter.Ishowyousomevariationsofdatasteps,soyouunderstandthembyexamples.
dataxyz;
setabc;
/*heremanipulationofdata*/
dataabc;
sethere.abc;
datahere.abc;
setxyz;
datathere.abc;
Reminder:
Temporarydatasets:
FoundinWORKfolder.Theydisappearwhenasessionends..
Workfolder:
ClickonExplorerClickonLIBRARIESClickonWORK
TheHEREfolderandTHEREfolder:
HEREandTHEREarethearbitrarynamesthatIassignedbygivingLIBNAMEstatement.TheyrefertopathsthatIspecified.
7.Manipulatingvariablesindatasteps
WeuseaSASsampledatasetsashelp.Class(adatasetcalledClassstoredinSASHELPfolder)topracticecreatingnewvariables.Dothistofindoutwhatthisdatasethas:
proccontentsdata=sashelp.Class;
Yougetinformationbelow,tellingyouthatthedatasethasAGE,Height,Name,SEX,andweight.
#VariableTypeLenPos
ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ
3AgeNum80
4HeightNum88
1NameChar824
2SexChar132
5WeightNum816
Hereis