超经典的SAS BASE的笔记6Word文档下载推荐.docx
《超经典的SAS BASE的笔记6Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《超经典的SAS BASE的笔记6Word文档下载推荐.docx(25页珍藏版)》请在冰豆网上搜索。
![超经典的SAS BASE的笔记6Word文档下载推荐.docx](https://file1.bdocx.com/fileroot1/2022-12/11/acc4be8e-8a4e-406c-987e-a2b378f1bf5e/acc4be8e-8a4e-406c-987e-a2b378f1bf5e1.gif)
oDouble-doublespacestheprintedoutput.
oLabel-usesvariablelabelsascolumnheadings(variablenameisdefaultheading).
oNoobs-suppressestheobservationnumberintheoutput.
Example1Listcontainingallthevariablesandalltheobservations.
dataa;
inputyearsalescost;
profit=sales-cost;
cards;
19811213211021
19821982312928
19831698214002
19841843214590
;
run;
procprintdata=a;
title'
SimplePROCPRINTReport'
Example2RemovalofcolumnOBSandimpressionlimitedtothefirst5observations.
dataexprev;
inputRegion$State$Monthmonyy5.
ExpensesRevenues;
formatmonthmonyy5.;
datalines;
SouthernGAJAN9520008000
SouthernGAFEB9512006000
SouthernFLFEB95850011000
NorthernNYFEB9530004000
NorthernNYMAR9560005000
SouthernFLMAR95980013500
NorthernMAMAR9515001000
procprintdata=exprev(obs=5)noobs;
varmonthstateexpenses;
MonthlyExpensesforOfficesinEachState'
Example3InstructionIDwithnotsortedobservations
databid;
inputidage;
98765
68775
25455
23670
procprint;
Example4InstructionID,aftersortingoftheobservations.
databid2;
inputpat_idage;
procsort;
bypat_id;
*varpat_id;
idpat_id;
Example5Testofoneortheothercondition,instructionWHERE
databid3;
procprintnoobs;
varage;
whereage<
75;
Example6InstructionSUM.
datatrim;
inputvendor$moisquantiteCOMMA5.tot_vendorcomma11.2;
datalines;
Hollingsworth0453010,573.50
Hollingsworth051,12022,344.00
Hollingsworth051,03020,548.50
Jones041,11022,144.50
Jones0467513,466.25
Smith041,71534,214.25
Smith0651210,214.40
Smith061,00019,950.00
PROCPRINTDATA=trimNOOBS;
TITLE'
Totalofvariablesnames'
VARvendormoisquantitetot_vendor;
WHEREquantite>
500ORtot_vendor>
20000;
SUMquantitetot_vendor;
RUN;
Example7InstructionsSUMandBYstatement
datatrim2;
procsort;
byvendor;
PROCPRINTDATA=trim2NOOBS;
SummarybyVender'
Example8InstructionPAGEBYandSUMBY
datatrim3;
PROCPRINTDATA=trim3NOOBS;
SUMBYvendor;
PAGEBYvendor;
Pagebyoptioncontrolspageejectsthatoccurbeforeapageisfull.
Sumbyoptionlimitsthenumberofsumsthatappearinthereport.
Example9OptionswithLabel,Double,TitleandFootnote
PROCPRINTDATA=trim5NOOBSlabeldouble;
SummarybyVendor'
FOOTNOTE'
ResultsofData-trim4'
LABELvendor='
Vendor'
mois='
Mois'
quantite='
QuantityofVendor'
tot_vendor='
TotalofVendors'
TheFREQprocedureproducesone-,two-,…n-way(crosstabulation)frequencytables.
TheSASprocedurePROCFREQiscommonlyusedtoproducesummarydataintabularform.Itcanbeusedoneithercharacterornumericdata.Statisticalanalysiswillbefollowedlater.Sevenexamplesareshownhereusingthisprocedureonfreq_xdataset.ThefollowingisasummaryofoptionsandoptionalstatementsthatcanbeusedwithPROCFREQ.Optionalstatementscanbeinanyorder,whileoptionsareenteredattheendoftheTABLESstatement,following"
/"
andbefore"
"
NotethatthislistrepresentsonlyaportionofallavailabletotheuserfromSAS:
∙TABLES-optionalstatementforspecifyingthevariablestobeincludedintheanalysis.
∙WEIGHT-optionalstatementforspecifyingthevariablestobesummedforeachvalueofthevariablesspecifiedintheTABLESstatement.
∙MISSING-optiontoincludemissingvaluesinthecalculationswithinthetable.
∙MISSPRINT-optiontodisplaythemissingvaluesinthetableswithoutincludingtheminthecalculations.
∙LIST-optiontolistvaluesofvariablessidebysideratherthanintabularform.
∙OUT=-optiontocreateadatasetcontainingtheoutputgeneratedbytheTABLESstatement.
Therearesomeofoptions,Nofreq,Norow,Nocol,Nopercentetal.
Syntax:
PROCFREQoptions;
BYvariables;
TABLESrequests<
/options>
WEIGHTvariable;
Example1:
simpleoutput
datafreq_01;
inputname$sex$ageheight;
AllanM25174
BenM23176
ChristineF24164
DavidM32174
EdwardsM36178
Frank.38172
GloryF28166
HillM32170
JackM33172
Katy.26162
LilyF24169
PaulaF.163
procfreqdata=freq_01;
title1'
PROCFREQ:
example01'
title2'
Nokeywordsspecified'
Example2:
One-waytable
procfreqdata=freq_02;
tablessexage;
1-waytablesforsexandagespecifiedbyTABLESkeyword'
Example3:
2-waytables
procfreqdata=freq_03;
tablessex*age;
two-waytablesforsexandagespecifiedbyTABLESkeyword'
Example4:
2-waytableslistingofthevaluesofthevariablessidebyside
procfreqdata=freq_04;
tablessex*age/listmissing;
two-waytablesusinglistandmissing'
Example5:
3waytables
procfreqdata=freq_05;
tablesname*sex*age;
3waytable:
heightbyweight,controllingforname'
/*Thefirstvariablerepresentsthecontrolvariable*/;
Example6:
Weightdata
DATAfreq_06;
INPUTrater1rater2count;
DATALINES;
115
122
131
211
227
232
311
322
339
PROCFREQDATA=freq_06;
WEIGHTcount;
TABLErater1*rater2;
TITLE1'
weighteddata'
Example7:
Outoption
tablesage/out=freq_07;
createnewdatasetusingoutoption'
Example8:
Missing/Missprint
tablessex/missing;
/*misprint*/
Example9:
NLEVELS
inputagegrpsex$@@;
1F1F1M2M2M3F3F3F
procfreqdata=anlevels;
tablessex*agegrp/noprint;
ThisoptioninPROCFREQstatementisusedtodisplaythe“NumberofVariableLevels”.ByusingthisoptionswecangetthedistinctcountforeachvariablelistedintheTABLESstatement.ItisbesttouseNLEVELSandNNOPRINToptionsoptiontoknowthenumberoflevelsofvariablebeforeprintingthefrequencytableifthedatasetistoolargeinsizeandifyouunawareofwhatcouldbedistinctcountforeachvariable.
Example10:
CROSSLIST
displayscrosstabulationtablesinODScolumnformat.ThisoptioncreatesatablethathasatabledefinitionthatyoucancustomizebyusingtheTEMPLATEprocedure.
tablessex*agegrp/crosslist;
Warning:
youcannotspecifyboththeLISToptionandtheCROSSLISToptioninthesameTABLESstatement.
TheCROSSLISToptionlooksthesameasLISToption,buttherearefewdifferencesasshownbelow.
CROSSLISTLIST
StatisticsFREQUENCYFREQUENCY
PERCENTPERCENT
ROWPERCENTCUMULATIVEFREQUENCY
COLUMNPERCENTCUMULATIVEPERCENT
TotalsProducessubtotalsandfinaltotals.Nototals
RowswithDisplaythevariablelevelswithSuppressthevariablelevelswith
zerofrequencieszerofrequencies
zerofreq
PROCMEANSonlybeperformedonnumericdata
∙Thisproceduregivesthefollowingsummarystatistics(ifnooptionsarespecified)foreachvariablelistedintheVARstatement:
numberofobservations,mean,standarddeviation,minimumvalue,maximumvalue,andstandarderrorofthemean.
∙Options:
Youcanselectwhichstatisticsyouwanttohaveprintedfromthefollowinglist:
N,NMISS(numberofmissingvalues),MEAN,STD,VAR,MIN,MAX,SKEWNESS,KURTOSIS,lclmanduclmoptionsprodu