超经典的SAS BASE的笔记5Word下载.docx
《超经典的SAS BASE的笔记5Word下载.docx》由会员分享,可在线阅读,更多相关《超经典的SAS BASE的笔记5Word下载.docx(28页珍藏版)》请在冰点文库上搜索。
![超经典的SAS BASE的笔记5Word下载.docx](https://file1.bingdoc.com/fileroot1/2023-4/29/fd10f1e2-a360-46c4-bb54-af3ede1f82ec/fd10f1e2-a360-46c4-bb54-af3ede1f82ec1.gif)
∙comparison
∙logical,orBoolean
∙minimum
∙maximum
∙concatenation.
Whenusedtoperformarithmeticoperations,theplusandminussignsareinfixoperators.
2.InfixOperator
2.1Arithmeticoperators:
ArithmeticOperators
Symbol
Definition
Example
*
multiplication
wherebonus=salary*.10;
/
Division
wheref=g/h;
+
Addition
wherec=a+b;
-
subtraction
wheref=g-h;
**
exponentiation
wherey=a**2;
2.2Comparisonoperators:
Thefollowingtableliststhecomparisonoperators:
ComparisonOperators
MnemonicEquivalent
=
EQ
equalto
whereempnumeq3374;
^=or~=or¬
NE
notequalto
wherestatusnefulltime;
>
GT
greaterthan
wherehiredategt'
01jun1982'
d;
<
LT
lessthan
whereempnum<
2000;
GE
greaterthanorequalto
whereempnum>
=3374;
LE
lessthanorequalto
IN
equaltoonefromalistofvalues
wherestatein('
NC'
'
TX'
);
ornumin(‘3’,‘4’,‘5’)
2.3Others
2.3.1INOperator
TheINoperator,whichisacomparisonoperator,searchesforcharacterandnumericvaluesthatareequaltoonefromalistofvalues.Thelistofvaluesmustbeinparentheses,witheachcharactervalueinquotationmarksandseparatedbyeitheracommaorblank.
Forexample,supposeyouwantallsitesthatareinNorthCarolinaorTexas.Youcouldspecify:
wherestate='
orstate='
;
However,theeasierwaywouldbetousetheINoperator,whichsaysyouwantanystateinthelist:
Inaddition,youcanusetheNOTlogicaloperatortoexcludealist.Forexample,
wherestatenotin('
CA'
'
TN'
MA'
Example:
datain_ex;
inputstore$vcr_pricevcd_pricecd_player_price;
datalines;
future_shop169.9969.9979.99
sony_store179.9964.9984.99
radio_shack159.9964.9969.99
three_d174.9967.4974.99
electron174.9965.9969.99
datain_ex_2;
setin_ex;
*where/ifvcr_pricenotin(159.99,169.99);
run;
2.3.2Fully-BoundedRangeCondition
Afully-boundedrangeconditionconsistsofavariablebetweentwocomparisonoperators,specifyingbothanupperandlowerlimit.Forexample,thefollowingexpressionreturnstheemployeenumbersthatfallwithintherangeof500to1000(inclusive):
where500<
=empnum<
=1000;
YoucancombinetheNOTlogicaloperatorwithafully-boundedrangeconditiontoselectobservationsthatfalloutsidetherange.Notethatparenthesesarerequired:
wherenot(500<
=1000);
2.3.3BETWEEN-ANDOperator
TheBETWEEN-ANDoperatorisalsoconsideredafully-boundedrangeconditionthatselectsobservationsinwhichthevalueofavariablefallswithinaninclusiverangeofvalues.
Youcanspecifythelimitsoftherangeasconstantsorexpressions.Anyrangeyouspecifyisaninclusiverange,sothatavalueequaltooneofthelimitsoftherangeiswithintherange.ThegeneralsyntaxforusingBETWEEN-ANDis:
WHEREvariableBETWEENvalueANDvalue;
Forexample:
whereempnumbetween500and1000;
wheretaxesbetweensalary*0.30andsalary*0.50;
2.4Booleanoperators:
AlsocalledLogicaloperators
&
orandand|ororor^ornotnegation
TwocomparisonswithacommonvariablelinkedbyAND(operator)canbecondensedwithanimpliedAND.Forexample,thefollowingtwosubsettingIFstatementsproducethesameresult:
∙if16<
=ageand/orage<
=65;
=age<
2.5MINandMAXOperators
UsetheMINandMAXoperatorstofindtheminimumormaximumvalueoftwoquantities.
2.6ConcatenationOperator
Theconcatenationoperatorconcatenatescharactervalues.Youindicatetheconcatenationoperatorasfollows:
||
Forexample,inthisDATAstep,thevaluethatresultsfromtheconcatenationcontainsblanksbecausethelengthoftheCOLORvariableiseight:
datanamegame;
lengthcolorname$8game$12;
color='
black'
name='
jack'
*game=color||name;
game=trim(color)||name;
*putgame=;
run;
ThevalueofGAMEis'
blackjack'
.Tocorrectthisproblem,usetheTRIMfunctionintheconcatenationoperationasfollows:
game=trim(color)||name;
Thisstatementproducesavalueof'
blackjack'
forthevariableGAME
data_null_;
month='
sep'
year=99;
date=trim(month)||left(put(year,8.));
/*PUTfunctiontoconvertanumericvaluetoacharactervalue*/
putdate=;
3.SASexpressionandConditionalexpression(WHEREandIF)
IFexpression:
TheIFcommandcanonlybeusedinaDATAstep.Thismeansyouarecreatinganewdatasetthatincludesonlytheselectedobservations.OnlyobservationsthatsatisfytheIFconditionaresenttotheoutputdataset.
WHEREexpression:
isatypeofSASexpressionthatdefinesaconditionforselectingobservations.TheWHEREcommandcanbeaddedtoanyprocedure.OnlyobservationsthatsatisfytheWHEREconditionareusedbytheprocedure.UsingtheWHEREstatementmayimprovetheefficiencyofyourSASprogramsbecauseSASisnotrequiredtoreadallobservationsfromtheinputdatasetanddoesnotchangethedatasetinanyway.
4.1Mathematical:
ThefollowingisabriefsummaryofSASfunctionsusefulfordefiningmodels.
ABS(x)theabsolutevalueofx
COS(x)thecosineofx.xisinradians.
EXP(x)ex
LOG(x)thenaturallogarithmofx
LOG10(x)thelogbasetenofx
LOG2(x)thelogbasetwoofx
SIN(x)thesineofx.xisinradians.
SQRT(x)thesquarerootofx
TAN(x)thetangentofx.xisinradiansandisnotanoddmultipleof2.
4.2Statistical
Kurtosis:
describesthe“heavinessofthetails”ofadistribution
Skewness:
measureofthetendencyforthedistributionvaluestobemorespreadoutononesidethatother
MaxandMin:
Mean:
averageisthetotalofsumdividedbythenumberofscores
Median:
thepointthatcorrespondstothevaluethatliesinthemiddleofthedistribution
orthevaluethatdividesadistributionexactlyinhalf(3,5,8,10,11).Itservesasavaluablealternativetothemeaninthespecificsituations:
a)thereareafewextremescoresinthedistribution,b)somevalueshaveundeterminedvalues,c)whenthedataaremeasuredonanordinalscale(seeexamplebelow)
Range:
maxtomin
Sum:
Variance:
measureofvariability
Std:
standarddeviation,thesquarerootofthevariance
Stderr:
standarderrorofthemean,stddev/thesquarerootofsamplesize
dataincome_1;
inputregion$1-8income;
cards;
Edison99800
Edison109800
Edison120000
Edison96500
Edison90550
Edison115000
Edison142500
Edison73000
Edison79850
Edison55890
Edison23000
Edison19800
Edison82000
Edison76800
Edison39800
Edison22800
Edison58650
procunivariatedata=income_1plotnormal;
varincome;
procchartdata=income_1;
vbarincome/levels=8;
dataincome_2;
Edison11800
Edison29800
Edison15000
Edison26500
Edison39550
Edison22000
Edison62500
Edison83000
Edison29850
Edison35890
Edison53000
Edison72000
Edison36800
procunivariatedata=income_2plotnormal;
varincome;
procchartdata=income_2;
vbarincome/levels=10;
5.SASTimeandDate:
5.1SASDate,Time,andDatetimeValues
KeyConcepts:
SASdatevalue:
isavaluethatrepresentsthenumberofdaysbetweenJanuary1,1960,andaspecifieddate.SAScanperformcalculationsondatesrangingfromA.D.1582toA.D.19,900.DatesbeforeJanuary1,1960,arenegativenumbers;
datesafterarepositivenumbers.SASdatevaluesaccountforallleapyeardays,includingtheleapyeardayintheyear2000.VariousSASlanguageelementshandleSASdatevalues:
functions,formatsandinformats.
SAStimevalue:
isavaluerepresentingthenumberofsecondssincemidnightofthecurrentday.
SASdatetimevalue:
isaspecialvaluethatcombinesbothdateandtimeinformation.ASASdatetimevalueisstoredasthenumberofsecondsbetweenmidnightonJanuary1,1960,andagivendateandtime.
optionsnodatepageno=1linesize=80pagesize=60;
datatest;
Time1=86399;
/*datetimevalue*/;
formatTime1datetime.;
Date1=86399;
/*datevalue*/;
formatDate1date.;
Time2=86399;
/*timevalue*/;
formatTime2timeampm.;
procprintdata=test;
title'
SameNumber,DifferentSASValues'
Output:
ObsTime1Date1Time2
101JAN60:
23:
59:
5920JUL9611:
59PM
HowSASConvertsCalendarDatestoSASDateValues
5.2Two-DigitandFour-DigitYears
IfdatesinyourexternaldatasourcesorSASprogramstatementscontaintwo-digityears,youcandeterminewhichcenturyprefixshouldbeassignedtothembyusingtheYEARCUTOFF=systemoption.TheYEARCUTOFF=systemoptionspecifiesthefirstyearofthe100-yearspanthatisuse