View
227
Download
0
Category
Preview:
Citation preview
7/25/2019 SAS Functions by Example - Herman Lo
1/18
Examples fromExamples fromSAS Functions bySAS Functions by
ExampleExampleRon CodyRon Cody
Herman LoHerman Lo
Technical Analyst, RBC CapitalTechnical Analyst, RBC Capital
7/25/2019 SAS Functions by Example - Herman Lo
2/18
AgendaAgenda
Book StructureBook Structure
Examples from the BookExamples from the Book
Character Functions (CATS, CATXCharacter Functions (CATS, CATX
!ate an" Time Functions (#$TC%, #$T$X!ate an" Time Functions (#$TC%, #$T$X
!escripti&e Stats (#'R, SMAEST)AR*EST!escripti&e Stats (#'R, SMAEST)AR*EST
Special Functions (#$+T, +TSpecial Functions (#$+T, +T
Macro Functions (CA S-M+T, CAMacro Functions (CA S-M+T, CAS-M+TXS-M+TX
The .er"ictThe .er"ict
7/25/2019 SAS Functions by Example - Herman Lo
3/18
Book StructureBook Structure
T/C 0 ist of ChaptersT/C 0 ist of Chapters ist of +ro1ramsist of +ro1rams At the 2e1innin1 of each chapterAt the 2e1innin1 of each chapter
ist of Functionsist of Functions
#nsi"e each chapter#nsi"e each chapter For each functionFor each function
+urpose+urpose SyntaxSyntax Examples)Anticipate" /utputsExamples)Anticipate" /utputs
A Sample +ro1ramA Sample +ro1ram At the 2ackAt the 2ack
ist of Functionsist of Functions #n"ex (Alpha2etical#n"ex (Alpha2etical
7/25/2019 SAS Functions by Example - Herman Lo
4/18
Character FunctionsCharacter Functions
CATS(string-1, string-2 )CATS(string-1, string-2 ) 3oins strin1s, strippin1 2oth lea"in1 an" trailin13oins strin1s, strippin1 2oth lea"in1 an" trailin1
2lanks2lanks
CATX(string-1, string-2 )CATX(string-1, string-2 ) 3oins strin1s, strippin1 2oth lea"in1 an" trailin13oins strin1s, strippin1 2oth lea"in1 an" trailin12lanks, an" a"" a space in 2et4een them2lanks, an" a"" a space in 2et4een them
ExampleExample
A 5 6Star7A 5 6Star7
B 5 68ars7B 5 68ars7
CATS(A, B 5 6Star8ars7CATS(A, B 5 6Star8ars7
CATX(A, B 5 6Star 8ars7CATX(A, B 5 6Star 8ars7
(See +19 :;
7/25/2019 SAS Functions by Example - Herman Lo
5/18
ate and !ime Functionsate and !ime Functions
INTCK(interval ReturnsReturns numbernumberofof IntervalsIntervals 2et4een2et4een
%ate1%ate1
an"an"
%ate2%ate2
&ate1 an% &ate2&ate1 an% &ate2 can 2ecan 2e date, time, datetimedate, time, datetime&alues&alues datedate>> $'1N2'''$%$'1N2'''$%
time:time: $*+1+'*$T$*+1+'*$T
datetimedatetime+$'1N2'''+*+1+'*$&T+$'1N2'''+*+1+'*$&T
Interval T"e unit .# t"e intervalInterval T"e unit .# t"e interval Interval(Interval(datedate) &A/, 0K, 0K&A/, ) &A/, 0K, 0K&A/,
Interval(Interval(timetime) SCN&, MINT, 34) SCN&, MINT, 34
Interval(Interval(datetimedatetime) &T&A/, &T0K, &T0K&A/, ) &T&A/, &T0K, &T0K&A/,
7/25/2019 SAS Functions by Example - Herman Lo
6/18
ate and !ime Functionsate and !ime Functions
INTCK(interval%ate1,%ate2)%ate1,%ate2) MultipleMultiple(optional)(optional) "ultiple"ultiple ofof intervalintervalunitunit
!A-:? 5 :?
S"i#t(optional)(optional) starting pointstarting point ofof intervalinterval Meanin1 of S"i#t"epen"s on the Interval
Interval/A4,SMI/A4,5T4,MNT3 S"i#t5 MNT3 -EAR@9 5 @
7/25/2019 SAS Functions by Example - Herman Lo
7/18
ate and !ime Functionsate and !ime Functions
INTCK(interval%ate1,%ate2)%ate1,%ate2)
ExamplesExamples
INTCK(/A4!6$,$'MA/2''2$%, $172''2$%)1INTCK(/A4!6$,$'MA/2''2$%, $172''2$%)1
INTCK(0K$,$'1AN1*8'$%, $'9AN1*8'$%)1INTCK(0K$,$'1AN1*8'$%, $'9AN1*8'$%)1
?3A$D? is a Sun"ay, so the 4eek counter is tri11ere"?3A$D? is a Sun"ay, so the 4eek counter is tri11ere"
2ecause "efault 8EE% startin1 point is Sun"ay92ecause "efault 8EE% startin1 point is Sun"ay9
CAREF>CAREF>
Results may surprise you (oG
7/25/2019 SAS Functions by Example - Herman Lo
8/18
ate and !ime Functionsate and !ime Functions
INTNX(interval$,start-INTNX(interval$,start-
%ate,in:re;ent
7/25/2019 SAS Functions by Example - Herman Lo
9/18
escripti#e Statsescripti#e Stats
I54(
7/25/2019 SAS Functions by Example - Herman Lo
10/18
escripti#e Statsescripti#e Stats
SMA77ST=7A4>ST(N,ST(N,ST(1,X1,X2,X,X9)7A4>ST(1,X1,X2,X,X9)
7/25/2019 SAS Functions by Example - Herman Lo
11/18
Special FunctionsSpecial Functions
IN?T(value, in#.r;at)IN?T(value, in#.r;at) +erforms character
7/25/2019 SAS Functions by Example - Herman Lo
12/18
Special FunctionsSpecial Functions?ri;arB #un:ti.ns+ ?T, IN?T?ri;arB #un:ti.ns+ ?T, IN?T
?4C D4MAT?4C D4MAT
@A7 ITM@A7 ITM
1A??7$1A??7$2?A4$2?A4$
>4A?$>4A?$
T34NKN0N$T34NKN0N$
@A7 ECST@A7 ECST
A$ F C$ $99!9$A$ F C$ $99!9$
&$ 12!$&$ 12!$
T34 T34
4N4N
&ATA TAG7&ATA TAG7
IN?T ITMHN C& E IN?T ITMHN C& E
ITMHNAM ITMHNAM PUTPUT(ITMHN, ITM!)(ITMHN, ITM!)
AMNT AMNT INPUT(PUTINPUT(PUT(C&, ECST!), *!)(C&, ECST!), *!)
&ATA7INS&ATA7INS
1 G1 G2 & X 9 C2 & X 9 C
?4C ?4INT &ATATAG7 NGS?4C ?4INT &ATATAG7 NGS
TIT7 J7isting .# &ata Set TAG7TIT7 J7isting .# &ata Set TAG7
4N4N
7isting .# &ata Set TAG77isting .# &ata Set TAG7
ITMHNITMHN C&C& ITMHITMH
NAMNAM
AMNTAMNT
11 GG A??7A??7 99!999!9
22 && ?A4?A4 12!''12!''
XX >4A?>4A? !!
99 CC NKN0NNKN0N 99!999!9
7/25/2019 SAS Functions by Example - Herman Lo
13/18
"acro Functions"acro Functions CA77 S/M?T(;a:r.-var, :"ara:ter-value)CA77 S/M?T(;a:r.-var, :"ara:ter-value)
CA77 S/M?TX(;a:r.-var, :"ara:ter-value)CA77 S/M?TX(;a:r.-var, :"ara:ter-value)
Assi1ns a &alue to a macro &aria2le "urin1Assi1ns a &alue to a macro &aria2le "urin1
execution of !ATA stepexecution of !ATA step
CA S-M+TX> Blanks are not remo&e" fromCA S-M+TX> Blanks are not remo&e" from&alue 2efore assi1nment to macro &aria2le&alue 2efore assi1nment to macro &aria2le
CA S-M+TX> ea"in1 K trailin1 2lanks areCA S-M+TX> ea"in1 K trailin1 2lanks are
remo&e" from &alue 2efore assi1nment to macroremo&e" from &alue 2efore assi1nment to macro
&aria2le&aria2le
EIui&alent toEIui&alent to LletLletstatement in macro lan1ua1estatement in macro lan1ua1e
7/25/2019 SAS Functions by Example - Herman Lo
14/18
.alue of 8#TBA$%S is
7/25/2019 SAS Functions by Example - Herman Lo
15/18
File &'$ FunctionsFile &'$ Functions
File #)/ functions are use" to o2tain information a2out SAS "ataFile #)/ functions are use" to o2tain information a2out SAS "atasetssets
%si% ?N(%ata-set-na;e$
7/25/2019 SAS Functions by Example - Herman Lo
16/18
File &'$ FunctionsFile &'$ Functions
ATT4C(%si%,$attriPute$)ATT4C(%si%,$attriPute$)
Returns theReturns the charactercharacter&alue of a character type attri2ute&alue of a character type attri2ute
i9e9i9e9 ATT4C(&SI&, s.rte%PB$)ATT4C(&SI&, s.rte%PB$)5 name of the B- &aria2le95 name of the B- &aria2le9
Empty if not sorte"9Empty if not sorte"9
ATT4N(%si%,$attriPute$)ATT4N(%si%,$attriPute$)
Returns theReturns the numericnumeric &alue of a character type attri2ute&alue of a character type attri2ute
7/25/2019 SAS Functions by Example - Herman Lo
17/18
File &'$ FunctionsFile &'$ FunctionsLMAC4 NGS(&SN)LMAC4 NGS(&SN)
ID XIST(JO&SN) T3N &ID XIST(JO&SN) T3N &
&SI& ?N(JO&SN)&SI& ?N(JO&SN)
NGSATT4N(&SI&,AN/)NGSATT4N(&SI&,AN/)
NGSATT4N(&SI&,N7GS)NGSATT4N(&SI&,N7GS)
NGSATT4N(&SI&,N@A4S)NGSATT4N(&SI&,N@A4S)
N&N&
7S NGS!7S NGS!4C C7S(&SI&)4C C7S(&SI&)
LMN& NGSLMN& NGS
&ATA HN77H&ATA HN77H
LNGS(TAG7)LNGS(TAG7)
?T AN/?T AN/
?T N7GS?T N7GS
?T N@A4S?T N@A4S4N4N
ITMHNITMHN C&C& ITMHITMH
NAMNAM
AMNTAMNT
11 GG A??7A??7 99!999!9
22 && ?A4?A4 12!''12!''
XX >4A?>4A? !!
99 CC NKN0NNKN0N 99!999!9
7isting .# &ata Set TAG77isting .# &ata Set TAG7
A$-5 (in"icates that "ataset has 2oth o2ser&ations an" &aria$/BS5@ ("ataset has @ lo1ical o2ser&ations
$.ARS5@ ("ataset has @ &aria2les
SAS L$%
7/25/2019 SAS Functions by Example - Herman Lo
18/18
!he (erdict!he (erdict
The 2ook is an excellent an"2ookThe 2ook is an excellent an"2ook
on SAS Functionson SAS Functions
$e4 SAS9 Functions are$e4 SAS9 Functions are
"emonstrate""emonstrate"
8hat # 4ish it has>8hat # 4ish it has>An associate" 4e2 resource)soft4areAn associate" 4e2 resource)soft4are
help manual for ease of lookuphelp manual for ease of lookup
Recommended