38
Learning SAS Lesson 1: http://www.youtube.com/watch?v=dwKfZq9lPFM SAS Interface: 1 box divided into 2, 1 st part has 2 tabs like EXPLORER & RESULTS. 2 nd part has 3 tabs: OUTPUT, LOG & EDITOR. Explorer: has files and libraries etc: every assignment in library is assigned a default name as WORK and it displays results same as in excel sheet. Results: it shows the subsidiary results file. Every time a change in code is made a new result is created. Editor: here we write the code to be executed like, Data main; main is name of the data set x=1; it is the observation run; proc print data=main; proc = procedure and then print the data main run; Output: it shows the output sets of the code. The output of above code is: Observation X 1 1

Sas

Embed Size (px)

DESCRIPTION

sas

Citation preview

Learning SASLesson 1:http://www.youtube.com/watch?v=dwKfZq9lPFMSAS Interface:1 box dvded !to "# 1$t pa%t ha$ " tab$ l&e '(P)*+'+ , +'-.)/-. "!d pa%t ha$ 0 tab$: *./P./# )*1 , '23/*+.Explorer: ha$ 4le$ a!d lb%a%e$ etc: eve%y a$$5!me!t ! lb%a%y $ a$$5!ed a default !ame a$ 6*+K a!d t d$play$ %e$ult$ $ame a$ ! excel $heet.Results: t $how$ the $ub$da%y %e$ult$ 4le. 've%y tme a cha!5e ! code $ made a !ew %e$ult $ c%eated.Editor: he%e we w%te the code to be executed l&e#2ata ma!7 ma! $ !ame of the data $etx=17 t $ the ob$e%vato!%u!7p%oc p%!t data=ma!7p%oc = p%ocedu%e a!d the! p%!t the datama!%u!7Output: t $how$ the output $et$ of the code./he output of above code $: *b$e%vato!( 1 1Log: t $how$ the detal$ of what ha$ bee! do!e ! o%de% to execute the code a!d what the ob$e%vato! !o. etc detal$ a%e.Lesson 2:http://www.youtube.com/watch?v=MFd8w+o9:xwSAS Code:/he above code $ $mple o!e a$ ! o!e value fo% o!e va%able. ;ut f we ca! mo%e tha! o!e va%able the! u$e code:2ata ma!7data $et $ ma!#3!put x y a%d$7ca%d$ $ u$ed befo%e me!to!!5 the data value$ fo% the$e va%able$ " ? @Aalue$8 B 97+u!7P%oc p%!t data=ma!7 p%ocedu%e p%!t$ the data $et+u!7/he output $:*b$e%vato!(CZ1 "?@" 8B9DEl$o $tateme!t p%oc co!te!t$ data=ma! $how$ the co!te!t$ of the p%o5%am a$ ! the !o. of ob$e%vato! o% the !o. of value$ etc.Lesson 3:http$://www.youtube.com/watch?v=?.aEl)8AwCFImporting External Data:1 !rom "ext #le:$% "E&'LA"ED CODE: txt #le t(pe) *it+ or *it+out delimiters %$data Gapp%op%ate data $et !ame he%eH7 !4le IGyou% 4le locato! he%e# !clud!5 .txt exte!$o!HI )+'>)=Ga lo5cal le!5th of you% data to emcompa$$ 'J/3+' dataH %for eg) in a,o-e code t+e lengt+ is . /x space ( space 01 ,ut *e *rite 122 and depending on t+e data (ou can *rite2)M=K#K7%DL&3Deliminator li4e comma space etc to ,e used in t+e data li4e x ( 0 or x)()0 so li4e *ise *e can include comma or space *e used space!putGva%able !ame$ he%eH7%u!75e used:data !4leLma!7!4le I>:MMy -E- Fle$Mma!.txtI)+'>)=1FF2)M=N O7!put x y lea! up va%able$ u$!5 a )E;') $tateme!t wth! a 2E/E -/'P D/data clea!Lma!7 $et clea!Lma!7 Eset is done on same dataset opposed to earlier onesFlabel 32 = I3de!t4cato! Jumbe%I mo!th = IMo!th of the Cea%I day = I2ay of the Cea%I7%u!7p%oc co!te!t$ data=ma!7Gcontents no* s+o* a ne* +eading called la,el *it+ eac+%u!7p%oc co!te!t$ data=clea!Lma!7 -aria,le called ,( t+e mentioned la,el in codeF%u!7-o f we %u! code:p%oc f%eq data=clea!Lma!7table mo!th7%u!76e 5et:Mo!th of the yea% UlabelVMo!th$ F%eque!cy>umulatve etcetc"1B 1$% J !OR&A" -alue la,els using t+e 'ROC !OR&A" and !OR&A" statements %$P+*> F*+ME/7value mo!th$. 1=IWa!ua%yI "=IFeb%ua%yI 0=IMa%chI ?=IEp%lI :=IMayI @=IWu!eI 8=IWulyI B=IEu5u$tI 9=I-eptembe%I 1F=I*ctobe%I 11=IJovembe%I 1"=I2ecembe%I7%u!7data clea!Lma!7E+ere *e are not c+anging t+e -alue of 1 to Aanuar( onl( formatting itF$et clea!Lma!7fo%mat mo!th mo!th$.7E:ere mont+ is t+e -aria,le and mont+s/dot1 is t+e -alue of formatF%u!7Jow afte% %u!!!5 code:p%oc f%eq data=clea!Lma!7table mo!th7%u!76e 5et:Mo!th of the yea% UlabelVMo!th$ F%eque!cy>umulatve etcetcFeb%ua%y Ufo%mattedV1Eu5u$t Ufo%matted1%"+us *e get name of mont+s rat+er t+an numeric -alues And *e +a-e formatted it:elpful ;otes: 1. /he%e a%e two place$ you ca! %educe the data you a!aly >*J/'J/- $tateme!t ca! allow you to $ee the va%able$ l$ted ! the o%de% they we%e c%eated.Lesson J:+ttps:$$***(outu,ecom$*atc+=-39s,Dpm9>@Kg/he *!e -ample tT/e$t a!d /e$t!5 fo% Jo%malty:/odayK$ >ode:D/h$ example# ta&e! f%om 9u!t$be%5e% a!d ;ll!5$ley U19B9# p. "9FV# te$t$ whethe% the mea! le!5th of a ce%ta! type of cou%t ca$e $ mo%e tha! BF day$ by u$!5 "F %a!domly cho$e! ca$e$.7data tme7!put tme [[7ca%d$7?0 9F B? B8 11@ 9: B@ 99 90 9"1"1 81 @@ 9B 89 1F" @F 11" 1F: 9B7%u!7D 6hat doe$ the data loo& l&e?7p%oc p%!t data=tme7%u!7*utput:*b$/me1?0 "9F 0 B?? B8:11@@9: 8 B@ B 99 9 90 1F9"111"1 1" 81 10 @@ 1? 9B 1:89 1@ 1F" 18@F 1B11" 191F: "F9B/D /9' /T/'-/ P+*>'2.+' 63/9*./ 1+EP93> *P/3*J- D/DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD7D /9' J.)) 9CP*/9'-3-7DDDDDDDDDDDDDDDDDDDDDD7D 1. E$& you%$elf: 6hat $ the J.)) hypothe$$ UhFV?7D ". 3! th$ ca$e# the J.)) hypothe$$ $: Imea! le!5th of ca$e$ $ equal to BFday$I7D E)/'+JE/3A' 9CP*/9'-'-7DDDDDDDDDDDDDDDDDDDDDDDDD7D 1. E$& you%$elf: 6hat $ the E)/'+JE/3A' hypothe$$ Uh1#o% 9aV?7D ". 3! th$ ca$e# the E)/'+JE/3A' hypothe$$ $ that the mea! le!5th of ca$e$ $ 1+'E/'+ tha! BF day$7D 0. 6e ca! $ee that weK%e $ay!5 I5%eate% tha!I becau$e of the opto!: $de$= u. . mea!$ Iuppe%I o% above/ 5%eate% tha!7D ?. 3f we wa!ted to te$t that the mea! wa$ $mply 23FF'+'J/? 6eKd $pecfy I$de$ = "I7D :. 3f we wa!ted to te$t that the mea! wa$ )*6'+ tha! BF day$? 6eKd $pecfy I$de$ = )I fo% Ile$$ tha!I7D /9' )'A') *F -31J3F3>EJ>'7DDDDDDDDDDDDDDDDDDDDDDDDDDDD7D 1. 3! -tat$tc$# we mu$t $pecfy the level of $5!4ca!ce UalphaV.D ". +ou5hly# you ca! !te%p%et th$ a$ I/h$ co!clu$o! dd !ot occu% by cha!ce.ID 0. /he \pT$de of level of $5!4ca!ce $ called co!4de!ce U1TalphaV. D ?. 3tK$ commo! p%actce to u$e a! alphaTvalue of :] $o we ca! be I9:] co!4de!tI of ou% %e$ult$./he code fo% te$t!5:P+*> //'-/ 2E/E=/3M' 9F=BF -32'-=. E)P9E=F.F:7 AE+ /3M'7Gme!to! the va%ableU/3M'V to be te$tedH+.J7/D /9' /T/'-/ P+*>'2.+' 63/9 1+EP93> *P/3*J- D/DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD7D /9' J*+ME)3/C E--.MP/3*J T 1+EP93>E) EJE)C-3-7DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD7D 1. Mo$t $tat$tc$ ca! be cla$$4ed a$ ethe% Ipa%amet%cI o% I!o!Tpa%amet%cI7D ". Pa%amet%c $tat$tc$ have a! !he%e!t a$$umpto! that the data $ !o%mally d$t%buted.7D 0. +ou5hly# IJo%mally d$t%buted dataI $mply mea!$ that data fall !to a patte%! f you mea$u%e t ofte! e!ou5h7D ?. /hat patte%! $ 5e!e%ally a I;ell $haped cu%veI.7D :. Cou ca! te$t f the data $ !o%mally d$t%buted by loo&!5 at the h$to5%am of the data a!d u$!5 a XXTPlot.7D @. 3f tK$ !ot mmedately obvou$# u$e P+*> .J3AE+3E/'7/he code:*2- 1+EP93>- *J7 G1%aphc$ o!HP+*> //'-/ 2E/E=/3M' 9F=BF P)*/-U-9*69FV -32'-=. E)P9E=F.F:7AE+ /3M'7+.J7GE!d P)*/-U-9*69FV opto! mea!$ that we wa!t to $ee !o%mal d$t%buto!H*2- 1+EP93>- *FF7 G1%aphc$ o=HDJow ! the %e$ult$ w!dow u!de% the va%able tme the%e a%e two mo%e opto! $how!5 the 5%aphc$ of the $tat$tc$D /9' J*+ME)3/C E--.MP/3*J T J.M'+3>E) EJE)C-3-7DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD7D E$$e$$ !o%malty wth the E!de%$o!T2a%l!5 te$t UJull hypothe$$: data $ !o%mally d$t%butedV7/he code:p%oc u!va%ate data=tme7va% tme7h$to5%am /!o%mal7 D /h$ $ the %equ%ed l!e to 5et !o%malty te$t $tat$tc$7%u!7%;o* in t+e results section under -aria,le time) t+ere *ill ,e a su,folder of +istogram under *+ic+ t+ere *ill ,e a normal #t folder and in t+is clic4 on goodness of #t In t+is goodness of #t SAS uses 3 tests to calculate t+e normalit( of t+e statistics and in AndersonLdarling test see t+e p -alue and compare *it+ M to get t+e result:elpful ;otes: 1. /he //'-/ p%ocedu%e %equ%e$ the data be !o%mally d$t%buted.". -pecfy!5 the !ullThypothe$$ value a!d the alte%!atve hypothe$$ u$!5 the hF= a!d $de$= opto!$ o! the P+*> $tateme!t allow you to $pec4cally co!t%ol what you a%e te$t!5.0. -pecfy the level of $5!4ca!ce UalphaV u$!5 the alpha= opto! o! the P+*> $tateme!t.?. /o 5%aphcally v$ual $tep to $how the h$to5%am a!d XX plot$.:. )a$tly# fo%mal !o%malty a$$umpto!$ Uthe bette% %outeV ca! be do!e u$!5 the E!de%$o!T2a%l!5 te$t ! P+*> .J3AE+3E/'. +emembe% that the !ull hypothe$$ $ e$$e!tally that the data $ !o%mally d$t%buted# $o youKll wa!t to have a !o!T$5!4ca!t pTvalue to &!ow the data $ !o%mal.Lesson G:+ttps:$$***(outu,ecom$*atc+=-39LBK4>tID&>Pa%ed a!d /woT-ample t /e$t$:/odayK$ >ode: /D 3. PE3+'2 t /'-/ '(EMP)' D//D 3! th$ example# ta&e! f%om the -.13 -uppleme!tal )b%a%y .$e%K$ 1ude# Ae%$o! : 'dto!# a $tmulu$ $ be!5 exam!ed to dete%m!e t$ e=ect o! $y$tolc blood p%e$$u%e. /welve me! pa%tcpate ! the $tudy. 'ach ma!K$ $y$tolc blood p%e$$u%e $ mea$u%ed both befo%e a!d afte% the $tmulu$ $ appled. D/data p%e$$u%e7!put -;Pbefo%e -;Pafte% [[7datal!e$71"F 1"B 1"? 101 10F 101 11B 1"81?F 10" 1"B 1": 1?F 1?1 10: 1081"@ 11B 10F 10" 1"@ 1"9 1"8 10:7%u!7*utput of th$ code:*b$-;Pbefo%e-;Pafte%11"F 1"B "1"?101 0 10F 101 ? 11B 1"8: 1?F 10" @ 1"B 1": 8 1?F 1?1 B 10: 1089 1"@ 11B 1F 10F 10" 11 1"@ 1"9 1" 1"8 10:D J*/': /93- 3- PE3+'2D 2E/E ;'>E.-' /9' M'E-.+'- 2'P'J2 *J /9' -.;W'>/ 3! othe% wo%d$# whe! you have d=e%e!t mea$u%eme!t$ that a%e mea$u%ed o! the $ame $ub^ect# the data $ depe!de!t o! the $ub^ect a!d $ the%efo%e%elated to each othe%. E$ $uch# twoT$ample te$t$ a%e !app%op%ate becau$ethe data a%e !ot !depe!de!t of each othe%_7/D PE3+'2 / /'-/ 63/9*./ 1+EP93>- D/p%oc tte$t data=p%e$$u%e7pa%ed -;Pbefo%eD-;Pafte%7 %u!7*utput:Cou wll 5et the %e$ult$ a!d $ee the p value ! o%de% to accept o% %e^ect the hypothe$$ at :] level of $5!4ca!ce./D PE3+'2 / /'-/ 63/9 1+EP93>- D/od$ 5%aphc$ o!7p%oc tte$t data=p%e$$u%e7pa%ed -;Pbefo%eD-;Pafte%7 %u!7od$ 5%aphc$ o=7*utput:9e%e the h$to5%am a!d the XX plot $how$ the data to be !o%mal a!d t $hould be do!e to chec& a$ th$ te$t $ do!e o!ly o! !o%mal data.D /e$t fo% Jo%malty of 'ach Aa%able -epa%ately7p%oc u!va%ate data=p%e$$u%e7va% -;Pbefo%e -;Pafte%7h$to5%am /!o%mal7%u!7*utput:%;o* in t+e results section under -aria,le time) t+ere *ill ,e a su,folder of +istogram under *+ic+ t+ere *ill ,e a normal #t folder and in t+is clic4 on goodness of #t In t+is goodness of #t SAS uses 3 tests to calculate t+e normalit( of t+e statistics and in AndersonLdarling test see t+e p -alue and compare *it+ M to get t+e result/D 33. /6* -EMP)' t /'-/ '(EMP)' D//D 3! the follow!5 example# the 5olf $co%e$ fo% male$ a!d female$ ! a phy$cal educato! cla$$ a%e compa%ed. /he $ample $od!5 a!d Mac%o Aa%able$:/odayK$ >ode:data ma!7!put 32 va%1 va%"7ca%d$71 " 0" ? :0 @ 8? B 97%u!7p%oc co!te!t$ data=ma!7 %u!7 G$how$ co!te!t of the data$etH*utput of th$ code:*b$ 32 Aa%1 Aa%"11" 0" " ? :00 @8? ?B 9/D 1. >%eate a mac%o va%able u$!5 the ]let $tateme!t D/]let !ewva% = va%07 G] $5! mea!$ mac%o , t mea!$ -E- ca! call !ew va%able va%0 a!ytme o% we ca! call t a 5lobal va%ableH/D ". .$e the , ope%ato% to call a mac%o va%able D/data !ewLma!7 $et ma!7,!ewva% = va%1Yva%"7G$ame a$ va%0 = va%1 Y va%" but ,!ewva% th$ mac%o way of do!5H%u!7p%oc co!te!t$ data=ma!7 %u!7p%oc co!te!t$ data=!ewLma!7 %u!7p%oc p%!t data=!ewLma!7%u!7*utput of th$ code:*b$ 32 Aa%1 Aa%"Aa%011" 0 :" " ? :900 @810? ?B 918/D 0. >%eate a mac%o to t%a!$fo%m a va%able D/]ME>+* t%a!$fo%mLth$UxV7 G!ew fu!cto! to t%a!$fo%m xH,x.L$qua%ed = ,x DD "7 Gwhch $ $qua%e of ( a!d >ube of ( , !ve%$e of (H,x.Lcubed = ,x DDD 07 GdotU.V mple$ addto!al !fo%mato! fo% xH,x.L!ve%$e = 1 / ,x7]M'J2 t%a!$fo%mLth$7Gope!!5 ]mac%o , clo$!5 ]me!dHdata !ewe%Lma!7 $et !ewLma!7]t%a!$fo%mLth$Uva%1V7%u!7p%oc p%!t data=!ewe%Lma!7%u!7*utput:*b$ 32 Aa%1 Aa%"Aa%1L$qua%ed va%1Lcubedva%1L!ve%$e11 "0?B F.:" " ? : 1@ @?F.":00 @8 0@"1@ F.1@@8? ?B9@? :1" F.1":/D ?. >%eate a mac%o to %u! the >*J/'J/- p%ocedu%e o! a!y data $et D/p%oc co!te!t$ data=ma!7 %u!7p%oc co!te!t$ data=!ewLma!7 %u!7p%oc co!te!t$ data=!ewe%Lma!7 %u!7]ME>+* co!te!t$LofUdataL$etV7p%oc co!te!t$ data=,dataL$et7 %u!7]M'J2 co!te!t$Lof7]co!te!t$LofUma!V7]co!te!t$LofU!ewe%Lma!V7*utput:3t $how$ the co!te!t$ of the data $et ma! , !ewLma! %e$pectvely.$% . Create a macro to run t+e 'RI;" procedure on an( data set %$]ME>+* p%!tLth$UdataL$etV7p%oc p%!t data=,dataL$et7 %u!7]M'J2 p%!tLth$7]P%!tLth$Uma!V7] P%!tLth$ U!ewe%Lma!V7*utput:*b$ 32 Aa%1 Aa%"11" 0" " ? :00 @8? ?B 9C*b$ 32 Aa%1 Aa%"Aa%1L$qua%ed va%1Lcubedva%1L!ve%$e11 "0?B F.:" " ? : 1@ @?F.":00 @8 0@"1@ F.1@@8? ?B9@? :1" F.1"::elpful ;otes: 1. /he%e a%e two place$ o!e ca! u$e mac%o va%able$: wth! a mac%o# a!d 5lobally out$de of all -/'P-.". /he ampe%$a!d ope%ato%: ,# de4!e$ a mac%o va%able wth! a mac%o a!d $ u$ed to call mac%o va%able$ a!ywhe%e.0. /he ]let $tateme!t allow$ you to de4!e mac%o va%able$ out$de of a mac%o# thou5h the , ope%ato% $tll mu$t be u$ed to call the mac%o va%able el$ewhe%e.?. /he ME>+* $tateme!t be5!$ the de4!to! of a mac%o a!d the M'J2 e!d$ the de4!to!.:. 3t $ opto!al to %e$tate the mac%o !ame afte% the M'J2 $tateme!t.@. E mac%o ca! be thou5ht of a$ a fu!cto!# whe%e o!e pa$$e$ $ometh!5 !tothe fu!cto! a!d ce%ta! th!5$ a%e %etu%!ed. .!l&e a fu!cto!# howeve%# mac%o$ do !ot alway$ have to %etu%! $ometh!5. Lesson 12:+ttps:$$***(outu,ecom$*atc+=-3NCtAdcpImLoCindex312Clist3'LJCOKO??A2!o!45u%!5 the -E- '!v%o!me!t fo% 'bce!cy:9elpful Jote$: 1. '!ha!ced 'dto% co!45u%ato!1e!e%al:>ha!5e the /ab$ to " $pace$ a!d %eplace tab$ wth $pace$./h$ ca! help you o%5a!