You are on page 1of 59

Introduction Data types : In SAS there are just two data types: Numeric data can contain plus

signs (+), minus signs (-), decimal points (.), or E or scienti ic notation. Character data are e!erything else. "hey may contain numerals, #etters, or special characters (such as $ or %) and can &e up to '(,)*) characters long. ***************************Variables and observations************************ ************************************Missing data********************************* Rules for S S Names: SAS data set names can &e + to '( characters long must &egin with a letter (A,-, either uppercase or lowercase) or an underscore (.) can continue with any com&ination o num&ers, letters, or underscores. !ayout for S S "rograms: SAS statements are in ree ormat. "his means that they can &egin and end anywhere on a line one statement can continue o!er se!eral lines se!eral statements can &e on a line. Statement: A language who ollows the sas rules &e ore semicolon. "rogram: A group o statement is called program. D # "R$C steps: &egin with /A"A statements read and modi y data create a SAS data set %procedure& steps: &egin with 0123 statements per orm speci ic analysis or unction produce results or report

Statements Sample "rogram Code /A"A statement : data clinic.admit+4 SE" statement : set clinic.admit4 156 statement : run4 0123 01I6" statement : proc print data7clinic.admit(4 156 statement : run4

Comment "o ma8e your programs more understanda&le, you can insert comments into your programs. 9: 0rint the results :9 S S !ibraries: Sashelp is a permanent li&rary that contains sample data and other iles that control how SAS wor8s at your site. "his is a read-only li&rary. Sasuser is a permanent li&rary that contains SAS iles in the 0ro ile catalog that store your personal settings. "his is also a con!enient place to store your own iles. 'or( is a temporary li&rary or iles that do not need to &e sa!ed rom session to session.

#he S S 'indo)s: *ditor )indo): ;ou can use it to type in, edit, and su&mit SAS programs as well as edit other te<t iles such as raw data iles. In =indows operating en!ironments, the de ault editor is the Enhanced Editor. "he Enhanced Editor is synta< sensiti!e and color codes your programs ma8ing it easier to read and ind mista8es. !og )indo) contains notes a&out your SAS session, and a ter you su&mit a SAS program, any notes, errors, or warnings associated with your program as well as the program statements themsel!es will appear in the #og window. $utput I your program generates any printa&le results, then they will appear in the 2utput window. Results "he 1esults window is li8e a ta&le o contents or your 2utput window4 the results tree lists each part o your results in an outline orm. *+plorer "he E<plorer window gi!es you easy access to your SAS iles and li&raries. Ra)data: Internal ra) data I you type raw data directly in your SAS program, then the data are internal to your program. 5se the /A"A#I6ES statement to indicate internal data. *+ternal ra) data files 5sually you will want to 8eep data in e<ternal iles, separating the data rom the program. "his eliminates the chance that data will accidentally &e altered when you are editing your SAS program. 5se the I6>I#E statement to tell SAS the ilename and path, i appropriate, o the e<ternal ile containing the data. "he I6>I#E statement ollows the /A"A statement and must precede the I605" statement. A ter the I6>I#E 8eyword, the E<: /ata new4 In ile ?path@4 Input !ar-list4 1un4

Common options: C*N#*R , N$C*N#*R 3ontrols whether output are centered or le t-justi ied. /e ault: 3E6"E1. D #* , N$D #* 3ontrols whether or not today@s date will appear at the top o each page o output. /e ault: /A"E. !IN*SI-* . n 3ontrols the ma<imum length o output lines. 0ossi&le !alues or n are *A to (B*. /e ault !aries. N/M0*R , N$N/M0*R 3ontrols whether or not page num&ers appear on each page o SAS output. /e ault: 65CDE1. " 1*N$ . n Starts num&ering output pages with n. /e ault is +. " 1*SI-* . n 3ontrols the ma<imum num&er o lines per page o output. 0ossi&le !alues or n are +B to '()*). /e ault !aries. RI12#M R1IN . n Speci ies siEe o margin (such as F.)Bin or (cm) to &e used or !*3#M R1IN . n printing output. /e ault: F.FFin. 4* RC/#$33 . yyyy Speci ies the irst year in a hundred-year span or interpreting two-digit dates. /e ault: +G(F.

"racticals 3reate data: 2ptions nonum&er nodate pagesiEe7+B4 /ata new4 9:create HnewI data:9 Set sashelp.class4 9:read HclassI data in HsashelpI li&rary:9 1un4 0roc print data7new4 1un4 2ptions linesiEe7(FF4 /ata sasuser.new4 Set sashelp.class4 1un4 0roc print data7sasuser.new4 1un4 /ata E < c ! & n m4 Set sashelp.class4 1un4 data s!4 input name$+-( age '-A se<$B pos *4 cards4 9:print the output:9

9:print the output:9

aa(*m+ a&(Bm( ac(+ ' ad(J A 4 proc print4run4 data a4 input name$ age pos se<$4 cards4 as +( + m sd (+ ( g '( ' we (( A m 4 proc print4run4 data &4 input K+ name$ KB age4 cards4 ase +( sd (+ ge '( we (( 4 proc print4run4 data c4 input K+ name$ KB age KJse<$4 cards4 ase +( m sd (+ ge '( m we (( 4 proc print4run4 data d4 input name$+-A age B-) se<$J-G4 cards4 ase +( m sd (+ ge '( m we (( 4 proc print4run4 options yearcuto 7+GFF4 data yrcuto 4 input date ddmmyyJ.4 ormat date ddmmyy+F.4 cards4 (+9F(9AB (+9F(9+B (+9F(9+GJ+ 4

proc print4run4 Chapter56 /sing a 3I!*N M* Statement De ore you can read your raw data, you must point to the location o the e<ternal ile that contains the data. ;ou use the >I#E6ACE statement to point to this location. #o Do #his /se #his S S Statement *+ample Reference a SAS data library LIBNAME statement li&name libref 'SAS-datalibrary'; Reference an external file FILENAME statement ilename tests Lc:MusersMtmill.datL4 Informat: A in ormat is an instruction that sas uses to read the data !alue into the !aria&le 3ormat: A E<: :In ormat ormat4 /ata in orm4 Input date 4 In ormat date dateG.4 >ormat date dateG.4 3ards4 (+ e&+GJ+ 4 0roc print4run4 proc print data7 sashelp.class( irsto&s7( o&s7B)4 run4 Column input: we use column input when data are in i<ed column. !ist input: when data are not in i<ed column. +. Colon (:): it used when !alues are greater then J &ytes% (. Am!ersand ("): it is used when data !alues contain em&edded &lan8 3ormat input: we used ormat input when we 8now the starting point o !alues &ut data should &e in i<ed column Standard and Nonstandard Numeric Data Standard n#meric data !alues can contain only num&ers decimal points ormat is an instruction that sas uses to write the data !alue into the !aria&le

num&ers in scienti ic or E-notation (2.3E4, or e<ample) plus or minus signs. Nonstandard n#meric data includes !alues that contain special characters, such as percent signs (N), dollar signs ($), and commas (,) date and time !alues data in raction, integer &inary, real &inary, and he<adecimal orms. 3ormat Specifies #hese Values *+ample C$MM $%d that contain commas and decimal places commaJ.( D$!! R$%d that contain dollar signs, commas, and decimal places dollar*.( MMDD44$. as date !alues o the orm FG9+(9G) (CC//;;J.) or FG9+(9+GG) (CC//;;+F.) mmddyy+F. $% rounded to the nearest integer in w spaces ). $%d rounded to d decimal places in w spaces J.( &$% as character !alues in w spaces $+(.

9:list inut:9 data ampsd4 input id la!or O $+A. Puantity4 cards4 + chocolate chip +F ( oatmeal uniPue +( ' peanut &utter +A A sugar inest +* 4 proc print4run4 data january.sales4 input Item : $+(. Amount : commaB.4 datalines4 "ruc8s +,'J( Qans +,('B Sedans (,'G+ Sport5tility GJ) 4 proc print data7january.sales4 run4

----------------colon modi ier----------------------4 data a+4

I605" KLDreed:L /ogDreed :$(F.4 cards4 Cy dog Sam Dreed: 1ottweiler Qet Dills: $A)J 4 proc print4 run4 data a(4 I605" KLDreed:L /ogDreed $(F.4 cards4 Cy dog Sam Dreed: 1ottweiler Qet Dills: $A)J 4 proc print4 run4 data a'4 I605" KLDreed:L /ogDreed $4 cards4 Cy dog Sam Dreed: 1ottweiler Qet Dills: $A)J 4 proc print4 run4

"he line pointers7 slash (9) and pound-n (Rn), =hen data arrange in sePuence. E<: 9:5SE S#ASS(9):9 /A"A A4 I605" >6ACE $ #6ACE $9 A//1ESS $ +-+J9 3I"; $+F. S"A"E $ -I04 3A1/S4 SA3 QE1CA +++F 1I3SC26/ 12A/ DA6TA#21E UU B*FF+* VA3 SSA1CA +++I 1I3SC26/ 12A/ DA6TA#21E UU B*FF+* 4 0123 01I6"41564 88:5it hold the raw data record across the iteration o data step until the line pointer mo!es past at end o the line. E<4 data new4 input name $ score KK4 datalines4 a(&' EB!' c(g)

d)y' 4 proc print4 run4

895 it hold the raw data record in the input &u er until sas reaches the &ottom o the data step. E<4 data g4 input type $ K4 I> "ype 7 Lsur aceL "SE6 /E#E"E4 I605" "ype$+-J 6ame $O G-'* AC"ra ic 0C"ra ic4 cards4 reeway AFJ '*JA 'ABG sur ace Cartin #uther Uing Vr. Dl!d. +BGF +('A sur ace Droadway +(BG +(GF sur ace 1odeo /r. +JGF (F*) reeway *FJ ABJ' 'J*F reeway JFJ ('J* (B+J sur ace #a8e Shore /r. +BGF +('A sur ace 0ennsyl!ania A!e. +(BG +(GF 4proc print4run4

data h4 :input type $ K4 I> "ype 7 Lsur aceL "SE6 /E#E"E4 I605" "ype$+-J 6ame $O G-'* AC"ra ic 0C"ra ic4 cards4 reeway AFJ '*JA 'ABG sur ace Cartin #uther Uing Vr. Dl!d. +BGF +('A sur ace Droadway +(BG +(GF sur ace 1odeo /r. +JGF (F*) reeway *FJ ABJ' 'J*F reeway JFJ ('J* (B+J sur ace #a8e Shore /r. +BGF +('A sur ace 0ennsyl!ania A!e. +(BG +(GF 4proc print4run4

1enerally: all the option are used in infile statement Infile :path name; option9 Infile cards option9 %if u r using e+ternal ra)data& % if u r using internal ra) data&

#he D!M. option: delimiter when data !alue are separated &y any recogniEe sym&ol li8e : (% R $ O : 9 , K :) etc.

/lm7@,@ /lm7@9@ /lm7@:@ /lm7@, 9 :@ or more then one delimiter. /lm7@FG@< i data separated &y ta& character. E<: data 4 in ile cards dlm7L,L4 input name$ age pos4 cards4 as,+(,+ sd,(+,( g,'(,' we,((,A 4 proc print4run4 data scores4 in ile cards dlm7L:L4 input name $ score+ score( score'4 datalines4 Voe:++:'(:)* Citchel:+':(G:J( Susan:+A:():)A 4 proc print4run4

data scores+4 in ile cards dlm7L:9:RL4 input name $ score+-score'4 datalines4 Voe:++:'(9)* Citchel:+':(G:J( Susan:+A:()R)A 4 proc print4run4

Missover : missing data at end o the record. E<: data e4 in ile cards dlm7L,Lmisso!er4 input name$ age num4 cards4 as,+(

sd,(+,( g,'( we,((,A 4 proc print4run4 Dsd : (delimiter sensiti!e data)when data separated &y comma and some or all !alue rounded &y Puotation mar8 then we use dsd option. E<: data a&c4 in ile datalines dsd4 input name $ id se< $4 datalines4 a,+,WmW & ,(,W W c,',WmW du,A,W W 4 proc print4run4 :use o misso!er dsd ---------------4 data aaa4 in ile datalines misso!er dsd 4 input name $ id se< $ num4 datalines4 a,+,WmW,BA & ,(,W W c,',WmW,*B du,A,W W 4 proc print4 run4

#runcover9 some data lines are shorter than others. 3irstobs: irsto&s used in in ile statement in data step and in option in proc step $bs:same as irsto&s. Descriptor "ortion "he descriptor portion o a SAS data set contains in ormation a&out the data set, including the name o the data set the date and time that the data set was created the num&er o o&ser!ations the num&er o !aria&les. Data "ortion "he data portion o a SAS data set is a collection o data !alues that are arranged in a

rectangular ta&le. Variable ttributes In addition to general in ormation a&out the data set, the descriptor portion contains in ormation a&out the attri&utes o each !aria&le in the data set. "he attri&ute in ormation includes the !aria&leLs name, type, length, ormat, in ormat, and la&el. !abel attributes: ! 0*! variable17'label1L variable2.<label2< ... 9 E<: /A"A un4 I605" Id 6ame $ Seight =eight /oD CC//;;J.4 #ADE# Id 7 LIdenti ication no.L Seight 7 LSeight in inchesL =eight 7 L=eight in poundsL /oD 7 L/ate o &irthL4 I6>21CA" /oD CC//;;J.4 >21CA" /oD CC//;;J.4 /A"A#I6ES4 B' Susie A( A+ F)-++-J+ BA 3harlie A* BB +F-(*-BA BB 3al!in AF 'B F+-+F-J+ B* #ucy A* B( F+-+'-BB 4 proc print4run4

proc print data7 un la&el4 !ar name height weight do&4 #ADE# Id 7 LIdenti ication no.L Seight 7 LSeight in inchesL =eight 7 L=eight in poundsL /oD 7 L/ate o &irthL4 run4

ssigning !ibrefs !I0N M* libref 'SAS-data-library'( where libref is + to J characters long, &egins with a letter or underscore, and contains only letters, num&ers, or underscores. *rror #ypes So ar, the programs that youL!e seen in this &oo8 ha!e &een error ree, &ut programming errors do occur. SAS can detect se!eral types o errors. "he most common are

synta+ errors that occur when program statements do not con orm to the rules o the SAS language data errors that occur when some data !alues are not appropriate or the SAS statements that are speci ied in a program. "his chapter ocuses on identi ying and correcting synta+ errors. Synta+ Chec(ing /uring the compilation phase, SAS also scans each statement in the /A"A step, loo8ing or synta< errors. Synta< errors include missing or misspelled 8eywords in!alid !aria&le names missing or in!alid punctuation in!alid options.

*+9 :--------length--------------------------4 data trn4 length designation $+(4 in ile datalines dlm7L,L4 input name $ height weight designation $ 4 datalines4 sneha,+*+,BA,student reema,+BA,AG,employee anil,+)*,*B,mathsteacher 4 proc print4 run4

Chapter5= Sas unction: unction per orm as a calculation, trans ormation o an arguments IN"/#%source,informat&: character to numeric E<: data inp4 input salary $4 newsal7input(salary,comma*.)4 cards4 '(,FFF (B,FFF +(,FFF (F,FFF 4 proc print4run4 "/#%source,format&: numeric to character E<: data puut4 input salary4 newsal7put(salary,dollar).)4 cards4 '(FFF (BFFF +(FFF (FFFF proc print4run4 compress the value: *+: data cp4 input phone $+-+'4 phone7compress(phone,L ().-L)4 cards4 ((*B-A*).(JG) 4 proc print4run4 #runcate function: IN# 3unction%floor& "o return the integer portion o a numeric !alue 1eneral form7 IN# function: IN#(argument)

R$/ND 3unction "o round !alues a ter decimal, use the R$/ND function. 1eneral form7 R$/ND function: R$/ND (argument round-off-unit) where argument is a numeric !aria&le, constant, or e<pression. round-off-unit is numeric and nonnegati!e. Ceil 3unction "o gi!e high !alue o integer portion Ceil (argument) data >I314 input tap4 <7 loor(tap)4 E7int(tap)4 y7ceil(tap)4 P7round(tap)4 cards4 +(.(B*B* 4 proc print4 run4 S S Date 3unctions: C/; date7mdy(mon,day,yr)4 "2/A; now7today()4 /A"E now7date()4 "ICE curtime7time()4 ;ou use other unctions to e<tract months, Puarters, days, and years rom SAS date !alues. 3unction #ypical /se Result /A; day7day(date)4 X"1 Puarter7Ptr(date)4 =EEU/A; w8day7wee8day(date)4 C26"S

month7month(date)4 ;EA1 yr7year(date)4 *+: data dmy4 input date.!alue4 day7day(date.!alue)4 month7month(date.!alue)4 year7year(date.!alue)4 cards4 +*)GF *F'*B +*)JG +*)G( 4 proc print4 run4 data all4 input a ddmmyy+F.4 day7/A;(a)4 Ptr7Ptr(a)4 today7"2/A;()4 yesterday7today()-+4 datetime7datetime()4 time7time()4 ormat today ddmmyy+F. yesterday ddmmyy+F. datetime datetime+G. time timeJ.4 cards4 FG9F'9+G*F +F9FA9+G*F ++9FB9+G*F +(9F*9+G*F 4 proc print4 run4 Modifying Character Values )ith 3unctions SC N : returns a speci ied word rom a character !alue. 1eneral form7 SC N function: SC N(argument n delimiters) where argument speci ies the character !aria&le or e<pression to scan n speci ies which word to read delimiters are special characters that must &e enclosed in single Puotation mar8s (L L). E<: :--------scan----------4 data a!i(drop7 mname)4 input name $+-+B4

mname7scan(name,(,L,L)4 name7le t(scan(name,+,L,L))4 mname7le t(scan( mname,(,L L))4 lname7le t(scan( mname,+,L L))4 ullname7cat<(L L, name,mname,lname)4 cards4 sachin,!erma 8 chetan,patel a 4 proc print4run4 S/0S#R : e<tracts a su&string or replaces character !alues. 1eneral form7 S/0S#R function: S/0S#R(argument !osition "n#) where argument speci ies the character !aria&le or e<pression to scan. !osition is the character position to start rom. n speci ies the num&er o characters to e<tract. I n is omitted, all remaining characters are included in the su&string. E<: data a&c4 input location $+-+B4 su&str(location,B,*)7L!armaL4 datalines4 goa dharma )J) 4 proc print4run4 #RIM trims trailing &lan8s rom character !alues. 1eneral form7 #RIM function: #RIM(argument) where argument can &e any character e<pression, such as a character !aria&le: trim%address& another character unction: trim%left%id&& E<: data lis4 input K+ name $ KAlname $4 ullname7trim( name)%%lname4 datalines4 3A" >ISS 4 proc print4run4 C #>:5 3oncatenates character strings, remo!es leading and trailing &lan8s, and inserts separators. 1eneral form7 C #> function: C #>(se!arator string-1 " ...string-nY ) where se!arator speci ies the character string that is used as a separator &etween concatenated strings

string speci ies a SAS character string. E<: data lise4 input K+ name $ KAlname $4 ullname7cat<(L L, name,lname)4 datalines4 3A" >ISS 4 proc print4run4 IND*> searches a character !alue or a speci ic string. 1eneral form7 IND*> function: IND*>(source e$cer!t) where source speci ies the character !aria&le or e<pression to search e$cer!t speci ies a character string that is enclosed in Puotation mar8s (L L). 3IND searches or a speci ic su&string o characters within a character string that you speci y. 1eneral form7 3IND function: 3IND(string substring" modifiers#" start!os# ) /"C S* con!erts all letters in a !alue to uppercase. 1eneral form7 /"C S* function: /"C S*(argument) E<: data lse4 input K+ name $4 name7upcase( name)4 datalines4 sachin 4 proc print4run4

!$'C S* con!erts all letters in a !alue to lowercase. 1eneral form7 !$'C S* function: !$'C S*(argument) E<: data ise4 input K+ name $4 name7lowcase( name)4 datalines4 3A">ISS 4 proc print4run4

#R N'RD replaces or remo!es all occurrences o a pattern o characters within a character string 1eneral form7 #R N'RD function: #R N'RD(source target re!lacement) E<: data a4 input dessart$+-++4 dessart7tranwrd(dessart,LappleL,Lpump8inL)4 datalines4 apple pie 4 proc print4run4 /sing I35#2*N statement: I> condition "SE6 action4 I action are more then one then we use I> codtion "SE6/2 Action4 Action4 E<: :--------i then else-----------4 data s4 input K+model $G.4 i model7LmarutiL then status7LlowL4 i model7L ordL then status7LmedL4 i model7LhondacityL then status7LhigL4 datalines4 maruti ord hondacity 4 proc print4run4 :----------i thendo else----------4 data a4 input K+model $G.4 i model7LmarutiL then do4 status7LlowL4 pos7L'L4 end4 else i model7L ordL then do4 status7LmedL4 pos7L(L4 end4 else i model7LhondacityL then do4 status7LhigL4 pos7L+L4 end4

datalines4 maruti ord hondacity 4 proc print4run4 R*# IN statement: TE" DA3U "SE QA#5E I6 A6A#;SIS 1etain !aria&le4 Qaria&le7sum(!aria&le, e<pression)4 Qaria&le+e<pression4 E<: data retan(drop7type)4 length type $+ dep $)4 input type $ K4 retain id4 i type7LeL then input id4 else input dep $4 i dep7L L then delete4 datalines4 e: +FF d: hindi d: english d: maths d: science 4 proc print4run4

rrays: arrays used to repetiti!e calculation in data. RR 4 statement: RR 4 array-name%dimension& "elements#; where array-name speci ies the name o the array. dimension descri&es the num&er and arrangement o array elements. "he de ault dimension is one. E<: data songs(drop7i)4 in ile datalines misso!er4 input K+name$ m+ m( m' mA mB 4 array m(B) m+-mB4 do i7+ to B4 i m(i)7. then m(i)7'4 end4 datalines4 al&ay ( A ) J . nethu + . G * +' &er8 B ) . G +' richmo ) G B . ++

4 proc print4run4 data son(drop7i)4 in ile datalines misso!er4 input K+name$ 8+ 8( 8' 8A 8B4 array 8(B) 8+-8B4 do i7+ to B4 i 8(i)7. then 8(i)7'4 end4 datalines4 al&ay ( A ) J . nethu + . G * +' &er8 B ) . G +' richmo ) G B . ++ 4 proc print4run4 /A"A songs4 I605" 3ity $ +-G Age dom8 wj hwow sim&h 8t aomm li&m tr ilp ttr4 A11A; old(+F) dom8 -- ttr4 /2 i 7 + "2 +F4 I> old(i) 7 G "SE6 old(i) 7.4 end4 cards4 Al&any BA A ' B G G ( + A A G 1ichmond '' B ( A ' G ( G ' ' ' 2a8land () + ' ( G G G ' A ( ' 1ichmond A+ A ' B B B ( G A B B Der8eley +J ' A G + A G ' G ' ( 40123 01I6" 4 1564

Chapter5? "rogram Data Vector A ter the input &u er is created, the program data vector is created. "he program data !ector is the area o memory where SAS &uilds a data set, one o&ser!ation at a time. #i8e the term input buffer, the term program data vector re ers to a logical concept. "he program data !ector contains two automatic variables that can &e used or processing &ut which are not written to the data set as part o an o&ser!ation. @N@ counts the num&er o times that the /A"A step &egins to e<ecute. @*RR$R@ signals the occurrence o an error that is caused &y the data during e<ecution. "he de ault !alue is ', which means there is no error. =hen one or more errors occur, the !alue is set to 1. "R$C S$R# AD # .SAS-data-set# out(new sas data set; R/N9 0123 S21" /A"A 7 messy 25" 7 neat 62/50UE;4 D; State /ES3E6/I6T 3ity4 1un4 1eneral form7 basic "R$C "RIN# step: "R$C "RIN# AD # .SAS-data-set#; R/N9 04 )ariable list9 "he D; statement starts a new section in the output or each new !alue o the D; !aria&les and prints the !alues o the D; !aria&les at the top o each section. "he data must &e presorted &y the D; !aria&les. ID )ariable list9 =hen you use the I/ statement, the o&ser!ation num&ers are not printed. Instead, the !aria&les in the I/ !aria&le list appear on the le t-hand side o the page. S/M )ariable list9 "he S5C statement prints sums or the !aria&les in the list. V R )ariable list9 "he QA1 statement speci ies which !aria&les to print and the order. =ithout a QA1 statement, all !aria&les in the SAS data set are printed in the order that they occur in the data set. " 1*04 )*-variable; where )*-variable identi ies a !aria&le that appears in the D; statement in the 0123 01I6" step. 0123 01I6" &egins printing a new page i the !alue o any o the !aria&les in the D; statement changes.

Double5Spacing !isting $utput I you are generating SAS listing output, one way to control the layout is to dou&le-space it. "o dou&le-space, speci y the D$/0!* option in the 0123 01I6" statement. proc print data7clinic.stress dou&le4 !ar resthr ma<hr rechr4

where tolerance7LIL4 run4 *+amples of '2*R* Statements Sere are some e<amples o =SE1E statements that use logical operators: where ageZ7BB and pulseY)B4 where area7LAL or region7LSL4 where I/Y+FBF and state7L63L4 =hen you test or multiple values of the same variable, you speci y the !aria&le name in each e<pression: )G where actle!el7L#2=L or actle!el7LC2/L4 where ee7+(A.JF or ee7+)J.(F4 ;ou can use the IN operator as a con!enient alternati!e: where actle!el in (L#2=L,LC2/L)4 where ee in (+(A.JF,+)J.(F)4 #I#!* and 3$$#N$#* Statements: "o ma8e your report more meaning ul and sel -e<planatory, you can speci y up to +F titles with procedure output &y using #I#!* statements &e ore the 0123 step. #i8ewise, you can speci y up to +F ootnotes &y using 3$$#N$#* statements &e ore the 0123 step. 6ote Decause "I"#E and >22"62"E statements are glo&al statements, place them &e ore the 01I6" procedure. "itles and ootnotes are assigned as soon as "I"#E or >22"62"E statements are read4 they apply to all su&sePuent output. 1eneral form7 #I#!* and 3$$#N$#* statements: #I#!*ZnY Lte$tL4 3$$#N$#*ZnY Lte$tL4 E<: 0123 S21" /A"A7SASSE#0.3#ASS 25"73#ASS+4 D; 6ACE4 1564 0123 01I6" /A"A73#ASS+4 QA1 6ACE SE[4 1564 20"I26S >I1S"2DS7+ 2DS7+F4 0123 S21" /A"A73#ASS 25"7A4 D; SE[4 1564 0123 01I6" /A"A7A4 QA1 6ACE SE[ ATE SEITS" =EITS"4 D; SE[4 I/ SE[4 S5C =EITS"4 "I"#E+LDI /E0A1"CE6"L4 "I"#E( LSAS 012T1ACCE1L4 >22"62"E+ LE6/L4 >22"62"E( L1E021"L4 1564 9:0ATE D1EAU:9

0123 01I6" /A"A7A4 QA1 6ACE SE[ ATE SEITS" =EITS"4 D; SE[4 0ATED; SE[4 S5C =EITS"4 "I"#E+LDI /E0A1"CE6"L4 "I"#E( LSAS 012T1ACCE1L4 >22"62"E+ LE6/L4 >22"62"E( L1E021"L4 1564 0123 01I6" /A"A7A4 QA1 6ACE SE[ ATE SEITS" =EITS"4 =SE1E ATE7+' A6/ SEITS" ZBG4 1564

#he C$N#*N#S "rocedure: ;ouL!e learned how to use SAS windows to !iew the contents o a SAS li&rary or o a SAS ile. Alternati!ely, you can use the C$N#*N#S procedure to create SAS output that descri&es either o the ollowing: the contents o a li&rary the descriptor in ormation or an indi!idual SAS data set. 1eneral form7 basic "R$C C$N#*N#S step: "R$C C$N#*N#S D # .librefB@ !!@ N$D*# I!S9 R/N9 where libref is the li&re that has &een assigned to the SAS li&rary. @ !!@ rePuests a listing o all iles in the li&rary. 5se a period (.) to append .A##. to the li&re . N$D*# I!S %N$DS& suppresses the printing o detailed in ormation a&out each ile when you speci y .A##.. ;ou can speci y 62/S only when you speci y .A##.. /sing the@N/!!@ Cey)ord Decause the goal o your SAS program is to create a raw data ile and not a SAS data set, it is ine icient to list a data set name in the /A"A statement. Instead, use the 8eyword .65##., which ena&les you to use the /A"A step without actually creating a SAS data set. A SE" statement speci ies the SAS data set that you want to read rom. data .null.4 "R$C 3$RM # statement: "R$C 3$RM # Zo!tionsY4 where o!tions includes !I0R R4.libref speci ies the li&re or a SAS data li&rary that contains a permanent catalog in which user-de ined ormats are stored 3M#!I0 prints the contents o a ormat catalog. 1eneral form7 V !/* statement: V !/* format-name range1('label1' range2('label2'

... 4 E<4 9:Speci y a SAS data set rom which 0123 >21CA" &uilds in ormats or ormats 36"#I67 :9 9:3reate a SAS data set that stores in ormation a&out in ormats or ormats 36"#25"7 :9 data ac4 input age se< income color $4 datalines4 +G + +AFFF y AB + *BFFF g )( ( 'BFFF & '+ + AAFFF y 4 proc ormat #ID7SAS5SE1 3"#25"7SAS5SE1.>C"4 !alue gender +7LmaleL (7L emaleL4 !alue agegroup +'-Z(F7LteenL (F-Z*F7LadultL *B-high7LseniorL4 !alue $col LyL7Lmoon whiteL L&L7Ls8y &lueL LgL7Lrain cloudy grayL4 1564 0123 >21CA" 36"#I67SAS5SE1.>C"4 1564 proc print data7ac4 ormat se< gender. age agegroup. color $col. income dollarJ.4 id color4 run4 9:"2 SEE >21CA":9 0123 >21CA" #ID7SAS5SE1 >C"#ID4 SE#E3" ATET12504 1564 #he C$N#*N#S "rocedure: ;ouL!e learned how to use SAS windows to !iew the contents o a SAS li&rary or o a SAS ile. Alternati!ely, you can use the C$N#*N#S procedure to create SAS output that descri&es either o the ollowing: the contents o a li&rary the descriptor in ormation or an indi!idual SAS data set. 1eneral form7 basic "R$C C$N#*N#S step: "R$C C$N#*N#S D # .librefB@ !!@ N$D*# I!S9 R/N9 where libref is the li&re that has &een assigned to the SAS li&rary. @ !!@ rePuests a listing o all iles in the li&rary. 5se a period (.) to append .A##. to the li&re . N$D*# I!S %N$DS& suppresses the printing o detailed in ormation a&out each ile when you speci y .A##.. ;ou can speci y 62/S only when you speci y .A##.. E[: proc contents data7SASSE#0.3#ASS4

run4 proc contents data7sasuser..all. nodetails4 run4 proc contents data7sasuser..all. nods4 run4

#he M* NS procedure "he CEA6S procedure pro!ides simple statistics on numeric !aria&les. #oo8 at some simple statistics. Statistics such as the mean !alue, standard de!iation, and minimum and ma<imum !alues gi!e you a eel or your data. "R$C M* NS data7 SAS-data-set# o!tions4 *!tions( M > the ma<imum !alue MIN the minimum !alue M* N the mean M*DI N the median N num&er o non-missing !alues NMISS num&er o missing !alues R N1* the range S#DD*V the standard de!iation S/M the sum Sere are some o the optional statements you may want to use in means procedure : 04 )ariable list9 "he D; statement per orms separate analyses or each le!el o the !aria&les in the list.+ "he data must irst &e sorted in the same order as the variable-list. (;ou can use 0123 S21" to do this.) C! SS )ariable list9 "he 3#ASS statement also per orms separate analyses or each le!el o the !aria&les in the list, + &ut its output is more compact than with the D; statement, and the data do not ha!e to &e sorted irst. V R )ariable list9 "he QA1 statement speci ies which numeric !aria&les to use in the analysis. I it is a&sent then SAS uses all numeric !aria&les. +,e *-+.-+ statement: >or summary statistics 25"05" 25" 7 data-set out!ut-statistic-list4 E<:0123 CEA6S /A"A 7 Eoo 6201I6"4 QA1 #ions "igers Dears4 25"05" 25" 7 Eoosum CEA6(#ions Dears) 7 #ion=eight Dear=eight4 1564

E<: /A"A QI15S4 I605" /I#5"I26 $ 32C0256/ $ "ICE KK4 I> /I#5"I267LAL "SE6 /#7+4 E#SE I> /I#5"I267LDL "SE6 /#7(4 E#SE I> /I#5"I267L3L "SE6 /#7A4 3A1/S4 A 0A J) A 0A GF A 0C J( A 0C )+ A 56 )( A 56 )) D 0A )G D 0A JF D 0C )' D 0C )( D 56 )F D 56 ** 3 0A )) 3 0A J+ 3 0C )( 3 0C *J 3 56 *( 3 56 *+ 4

0123 CEA6S /A"A7QI15S n mean min ma< nmiss median std 4 run4 0123 S21"4 D; 32C0256/4 run4 0123 CEA6S /A"A7QI15S4 QA1 "ICE4 3#ASS 32C0256/4 25"05" 25"725"A CEA67C S"/7S 673256"4 0123 01I6"4 1564 0123 S21"4 D; 32C0256/4 run4 0123 S5CCA1; /A"A7QI15S "RIN#4 QA1 "ICE4 3#ASS 32C0256/4 25"05" 25"725"D CEA67C S"/7S 673256"4 0123 01I6"4 1564 Counting 4our Data )ith "R$C 3R*D: It is analyEe the !aria&le compute statistics and compute association &etween the !aria&le thorough reP. E<:"R$C 3R*D data.Asas data setY4 # 0!*S variable-combinations4

# 0!*S ;earsEducation4 # 0!*S Se< : ;earsEducation4 !IS# prints cross-ta&ulations in list ormat rather than grid MISSIN1 includes missing !alues in rePuency statistics N$C$! suppresses printing o column percentages in cross-ta&ulations N$R$' suppresses printing o row percentages in cross-ta&ulations $/# . data-set writes a data set containing rePuencies E<: proc reP data7SASSE#0.3#ASS4 ta&les SE[:=EITS":height4 run4 proc reP data7SASSE#0.3#ASS4 ta&les SE[:=EITS":height9#IS"4 run4 proc reP data7SASSE#0.3#ASS4 ta&les SE[:=EITS"9#IS" 6212= 6232# 6235C 620E13E6"4 run4

"roducing #abular Reports )ith "R$C # 0/! #* It displays descripti!e statistics in ta&ulate ormat using some or all o the !aria&le in data set. "R$C # 0/! #*9 V R analysis-variable-list4 C! SS classification-variable-list4 # 0!* !age-dimension, row-dimension, column-dimension4 $perator action 3omma go to the new ta&le Dlan8 concatenate ta&le Asteris8 nested group Cey)ords In addition to !aria&le names, each dimension can contain 8eywords. "hese are a ew o the !alues "AD5#A"E can compute. A## adds a row, column, or page showing the total CA[ highest !alue CI6 lowest !alue CEA6 the arithmetic mean CE/IA6 the median 6 num&er o non-missing !alues 6CISS num&er o missing !alues 0GF the GFth percentile 03"6 the percentage o o&ser!ations or that group 03"S5C the percentage o a total sum represented &y that group S"//EQ the standard de!iation S5C the sum 3$RM #. option "o change the ormat o all the data cells in your ta&le, use the >21CA"7 option in your 0123 statement. >or e<ample, i you needed the num&ers in your

ta&le to ha!e commas and no decimal places, you could use this 0123 statement 0123 "AD5#A"E >21CA"732CCA+F.F4 0$>. and MISS#*>#. options "AD#E 1egion, CEA6:Sales 9 D2[7LCean Sales &y 1egionL CISS"E["7L6o SalesL4

E<: data &oats4 input name$+-) port$G-+B locomotion$+)-(( price ('-(B type$(*-(G4 datalines4 silent maalea sail )B sch america maalea sail '( yac aloha lahaina sail *( cat ocean maalea power B( cat anuenue maalae sail A) sch hana maalae power (J yac 4 proc ta&ulate data7&oats4 class locomotion type4 !ar price4 ta&le locomotion price type4 run4 proc ta&ulate data7&oats4 class locomotion type4 !ar price4 ta&le locomotion all price type all4 run4 9:little &it &est:9 proc ta&ulate data7&oats4 class locomotion type4 !ar price4 ta&le locomotion price, type all 9&o<7L ull day e<cursionL misste<t7LnoneL 4 title Lmean price &y locomotion and typeL4 run4 proc ta&ulate data7&oats4 class locomotion type4 !ar price4 ta&le locomotion, price, type all 9&o<7L ull day e<cursionL misste<t7LnoneL 4 title Lmean price &y locomotion and typeL4 run4 proc ta&ulate data7&oats4 class locomotion type4 !ar price4 ta&le locomotion all, mean:price:type all 9&o<7L ull day e<cursionL misste<t7LnoneL 4 title Lmean price &y locomotion and typeL4

run4 proc ta&ulate data7&oats4 class locomotion type4 !ar price4 ta&le locomotion all, mean:price:(type all) 9&o<7L ull day e<cursionL misste<t7LnoneL 4 title Lmean price &y locomotion and typeL4 run4 9:&est code:9 proc ta&ulate data7&oats4 class locomotion type4 !ar price4 ta&le locomotion all mean:price:(type all ) 9&o<7L ull day e<cursionL misste<t7LnoneL 4 title Lmean price &y locomotion and typeL4 run4 proc ta&ulate data7&oats4 class locomotion type4 !ar price4 ta&le locomotion mean:price:(type all ) 9&o<7L ull day e<cursionL misste<t7LnoneL 4 title Lmean price &y locomotion and typeL4 run4 proc ta&ulate data7&oats ormat7dollarG.(4 class locomotion type4 !ar price4 ta&le locomotion: mean:price:(type all ) 9&o<7L ull day e<cursionL misste<t7LnoneL 4 title Lmean price &y locomotion and typeL4 run4

"roducing Simple $utput )ith "R$C R*"$R# "o create list and summary report we use report procedure. In report procedure we can sort data we can modi y data. >ormat data. Troup report #ist report. =e can change la&el. So this procedure is integration o print sort ta&ulate and means. "R$C R*"$R# N$'IND$'S9 C$!/MN variable-list4 "R$C R*"$R# N$'IND$'S 2* D!IN* 2* DSCI"9 SEA/#I6E draws a line under the column headers while SEA/SUI0 puts a &lan8 line &eneath the column headers.

D*3IN* variable 9 o!tions +column-,eader+4 to modi y your !aria&le attri&ute . -efine o!tion. CR$SS creates a column or each uniPue !alue o the !aria&le. N !4SIS calculates statistics or the !aria&le. "his is the de ault usage or numeric !aria&les, and the de ault statistic is sum. DIS"! 4 creates one row or each o&ser!ation in the data set. "his is the de ault usage or character !aria&les. 1R$/" creates a row or each uniPue !alue o the !aria&le. $RD*R creates one row or each o&ser!ation with rows arranged according to the !alues o the order !aria&le. 0R* C location variable 9 o!tions4(S5D"2"A#) R0R* C location 9 o!tions4(T1A6" "2"A#) where location has two possi&le !alues BEF*RE or AF+ER Brea/ rbrea/ o!tions $! draws a line o!er the &rea8 " 1* starts a new page SCI" inserts a &lan8 line S/MM RI-* inserts sums o numeric !aria&les /! draws a line under the &rea8 "R$C R*"$R# compute options: M > highest !alue MIN lowest !alue M* N the arithmetic mean M*DI N the median N num&er o non-missing !alues NMISS num&er o missing !alues "EF the GFth percentile "C#N the percentage o o&ser!ations or that group "C#S/M the percentage o a total sum represented &y that group S#D the standard de!iation S/M the sum

E<: data &udget4 input X"1 KJ /E0" $+F. K(( A33256" $J. D5/TE" A3"5A#4 ormat actual &udget dollar++.( dept $+F.4 cards4 + Sta ulltime +'FFFF.FF +()*A(.*J ( Sta ulltime +*BFFF.FF +**'AB.)B + Sta parttime AFFFF.FF A'JBF.+( ( Sta parttime *FFFF.FF B*F+J.G* + EPuipment lease AFFFF.FF AFFFF.FF ( EPuipment lease AFFFF.FF AFFFF.FF + EPuipment purchase AFFFF.FF AJ(J(.'J ( EPuipment purchase (FFFF.FF +))*G.+B + EPuipment tape JFFF.FF *J(G.A(

( + ( + ( + ( + ( + ( + ( + ( + ( + ( + ( + ( 4

EPuipment EPuipment EPuipment EPuipment EPuipment EPuipment EPuipment >acilities >acilities >acilities >acilities >acilities >acilities "ra!el "ra!el "ra!el "ra!el 2ther 2ther 2ther 2ther 2ther 2ther

tape sets sets maint maint rental rental rent rent utils utils supplies supplies leases leases gas gas ad!ert ad!ert talent talent music ee music ee

+(FFF.FF )BFF.FF )BFF.FF +FFFF.FF +(FFF.FF AFFF.FF *FFF.FF (AFFF.FF (AFFF.FF BFFF.FF 'BFF.FF ()BF.FF ()BF.FF 'BFF.FF ABFF.FF JFF.FF +(FF.FF 'FFFF.FF 'FFFF.FF +'BFF.FF +GBFF.FF 'FFF.FF BFFF.FF

++A(*.)' J'A(.*J JF)G.*( )BA(.+' +F*)B.(G 'GGJ.J) BAJ(.GA (AFFF.FF (AFFF.FF A(('.(G 'AAA.J+ ((+*.BB ()A(.AJ 'FAB.+B 'JJG.*B B').(* GJA.G' '(A)*.GJ ')'(B.*A +(GJ*.)' +JA(A.*A (BBF.BF AJ)B.GB

data !ip4 input name$+-+) type$+G-(F region$((-(B pos (J-(G d 4 datalines4 diposaur nm west ( ' ellis island nm east ' B e!erglades np west ( ) statue o li&erty nm east + G yosemite np west ' ( hawaii !olcanoes np west ( ) 4 proc report data7!ip nowindows headline4 column name type region pos d 4 de ine type9width7A LtypeL4 de ine region9width7* LregionL4 de ine pos9 width7++ LpositionL4 run4 proc report data7!ip nowindows headline4 column name type region pos d 4 de ine type9group width7A spacing7B LtypeL right4 de ine region9group width7* spacing7B Lregion9wiseL center4 de ine pos 9width7++ LpositionL4 run4 proc report data7!ip nowindows headline split7L:L4 column name type region pos d 4 de ine type9order width7A spacing7B LtypeL right4 de ine region9order width7* spacing7B Lregion:wiseL center4 de ine pos 9width7++ LpositionL4

run4 proc report data7!ip headline nowindows CISSI6T4 column name type region pos4 de ine type 9order width7A4 de ine region9order width7*4 1D1EAU A>"E19S5CCA1I-E /2# /5# SUI04 run4 proc report data7!ip headline nowindows CISSI6T4 column name type region pos4 de ine type 9order width7A4 de ine region9order width7*4 :1D1EAU A>"E19S5CCA1I-E /2# /5# SUI04 run4 proc report data7wor8.&udget+ headline nowindows heads8ip4 column dept (&udget actual),sum 4 de ine dept9group 4 run4 proc report data7!ip nowindows headline CISSI6T4 column region type,(pos d )4 de ine type 9A312SS4 de ine region 9group4 run4 /A"A natpar8s4 in ile cards misso!er4 length name $+G type $( 1egion $A4 I605" 6ame $ "ype $ 1egion $ Cuseums 3amping4 cards4 /iposaur 6C =est ( * EllisIsland 6C East + F E!erglades 60 East B ( Trand3anyon 60 =est B ' TreatSmo8yCountains 60 East ' +F SawaiiQolcanoes 60 =est ( ( #a!aDeds 6C =est + + Statueo #i&erty 6C East + F "heodore1oose!elt 60 . ( ( ;ellowstone 60 =est G ++ ;osemite 60 =est ( +' 4 0123 1E021" /A"A 7 natpar8s 62=I6/2=S SEA/#I6E4 32#5C6 1egion "ype 6 (Cuseums 3amping),CEA64 /E>I6E 1egion 9 T12504 /E>I6E "ype 9 T12504 "I"#E LStatistics with "wo Troup Qaria&lesL4 1564 0123 1E021" /A"A 7 natpar8s 62=I6/2=S SEA/#I6E4 32#5C6 1egion "ype (Cuseums 3amping),mean4

:/E>I6E 1egion 9 T12504 :/E>I6E "ype 9 T12504 "I"#E LStatistics with "wo Troup Qaria&lesL4 1564 0123 1E021" /A"A 7 natpar8s 62=I6/2=S SEA/#I6E4 32#5C6 1egion 6 "ype,(Cuseums 3amping),CEA64 /E>I6E 1egion 9 group4 /E>I6E "ype 9 A312SS4 "I"#E LStatistics with a Troup and Across Qaria&leL4 1564 proc report data7wor8.&udget headline nowindows heads8ip out7&alance4 title+ L1eport o /epartmentsL4 title( L&y XuarterL4 column Ptr dept account &udget actual &alance4 de ine Ptr9order ormat7+. width7) LXuarterL4 de ine dept9order ormat7$+F. width7+F L/epartmentL4 de ine account9order ormat7$J. width7J LAccountL4 de ine &udget9display ormat7dollar++.( width7++ LAmount9DudgetedL4 de ine actual9display ormat7dollar++.( width7++ LAmount9SpentL4 de ine &alance9computed ormat7dollar++.( width7++ LDalanceL4 compute &alance4 &alance7&udget-actual4 endcomp4 &rea8 a ter Ptr9page4 run4 data &alance(drop7.&rea8.)4 set &alance4 i dep7@@ then delete4 run4 proc report data7&alance headline nowindows heads8ip4 column Ptr dept account &udget actual &alance4 de ine Ptr9order ormat7+. width7) LXuarterL4 de ine dept9order ormat7$+F. width7+F L/epartmentL4 de ine account9order ormat7$J. width7J LAccountL4 &rea8 a ter Ptr9suppress summariEe dol dul s8ip4 r&rea8 a ter 9 summariEe dol dul s8ip4run4

C2 "#*R5G %$/# "/# D*!IV*R4 S4S#*M&

$utput Delivery System%$DS&: 2utput /eli!ery System (2/S) which determines where the output should go and what it should loo8 li8e when it gets there. Some im!ortant destination. !IS#IN1 standard SAS output $/#"/# SAS output data set 2#M! Syperte<t Car8up #anguage R#3 1ich "e<t >ormat "D3 0orta&le /ocument >ormat M RC/" mar8up languages including [C# "he 2/S "1A3E statement "he 2/S "1A3E statement tells SAS to print in ormation a&out output o&jects in your SAS log. "here are two 2/S "1A3E statements: one to turn on the trace, and one to turn it o . Sere is how to use these statements in a program: $DS #R C* $N9 t,e /012 ste!s you want to trace go ,ere 1564 $DS #R C* $339 E[: /A"A ot4 I6>I#E datalines /S/4 I605" 6ame :$+B. 3olor $ /ays =eight4 datalines4 Dig -ac, red, JF, B /elicious, red, JF, ' /inner 0late, red, GF, ( Toliath, red, JB, +.B Cega "om, red, JF, ( Dig 1ain&ow, yellow, GF, +.B 0ineapple, yellow, JB, ( 4 2/S "1A3E 264 0123 CEA6S /A"A 7 ot4 D; 3olor4 1564 2/S "1A3E 2>>4

0123 "AD5#A"E /A"A 7 2"+4 3#ASS 3olor4 QA1 /ays =eight4 "AD#E 3olor A##, (/ays =eight) : CEA64 "I"#E LStandard "AD5#A"E 2utputL4 2/S 25"05" "a&le 7 ta&out4 1564

0123 01I6" /A"A 7 ta&out4 "I"#E L25"05" SAS /ata Set rom "AD5#A"EL4 1564 5sing 2/S Statements to 3reate S"C# 2utput: $DS statement: $DS 2#M! 0$D4 7 Lbody-filename.,tmlL o!tions4 C$N#*N#S. "he contents ile is a ta&le o contents with lin8s to the &ody ile. "he contents ile will list each part o your output, and when you clic8 on an entry in the ta&le o contents, that part o the output will appear. " 1*. "he page ile is similar to the contents ile, e<cept instead o la&eling the di erent parts o the output, it lists the output &y page num&er. 3R M*. "he rame ile allows you to !iew the &ody ile and the contents or the page ile at the same time in di erent areas, or rames, o the &rowser window. I you do not want either the contents or the page ile, then you don@t need to create a rame ile. S#4!*. "his option allows you to speci y a style template. "he de ault style is named /E>A5#". E[: 2/S S"C# D2/; 7 Lc:MCyS"C# ilesMCarineDody.htmlL 326"E6"S 7 Lc:MCyS"C# ilesMCarine"23.htmlL 0ATE 7 Lc:MCyS"C# ilesMCarine0age.htmlL >1ACE 7 Lc:MCyS"C# ilesMCarine>rame.htmlL4 /A"A marine4 I605" 6ame $ >amily $ #ength KK4 3A1/S4 &eluga whale +B dwar shar8 .B sperm whale *F &as8ing shar8 'F hump&ac8 whale BF whale shar8 AF gray whale BF &lue whale +FF 8iller whale 'F ma8o shar8 +( 4 0123 CEA6S /A"A 7 marine4 3#ASS >amily4 "I"#E L=hales and Shar8sL4 0123 01I6" /A"A 7 marine4 1564 2/S S"C# 3#2SE4 5sing 2/S Statements to 3reate 1"> 2utput: $DS statement: $DS R#3 3I!* 7 Lfilename.rtfL o!tions4 E[:

2/S 1"> >I#E 7 Lc:MCyS"C# ilesMCarine.rt L D2/;"I"#E4 0123 CEA6S /A"A 7 marine4 3#ASS >amily4 "I"#E L=hales and Shar8sL4 0123 01I6" /A"A 7 marine4 1564 2/S 1"> 3#2SE4 5sing 2/S Statements to 3reate 0/> 2utput: $DS statement: $DS "D3 3I!* 7 Lfilename.!dfL o!tions4 E[: 2/S 0/> >I#E 7 Lc:MCyS"C# ilesMCarine.pd L4 0123 CEA6S /A"A 7 marine4 3#ASS >amily4 "I"#E L=hales and Shar8sL4 0123 01I6" /A"A 7 marine4 1564 2/S 0/> 3#2SE4 3ustomiEing 0123 01I6" 2utput with the S";#E7 2ption: 0123 01I6" S";#E(location-list) 7 \style-attribute 7 value]4 0123 01I6" S";#E(/A"A) 7 \DA3UT1256/ 7 pin8]4 QA1 variable-list 9 S";#E(location-list) 7 \style-attribute ( value]4 E[: 2/S S"C# >I#E7Lc:MCyS"C# ilesMs8ating.htmL4 /A"A s8ating4 I6>I#E cards /S/ CISS2QE14 I605" ;ear 6ame :$(F. 3ountry $ "ime $ 1ecord $4 cards4 +GJJ,;!onne !an Tennip,6E/,):+A.+',=1 +GG(,Tunda 6iemann,TE1,):'+.B) +GGA,3laudia 0echstein,TE1,):+A.') +GGJ,3laudia 0echstein,TE1,*:BG.*+,=1 (FF(,3laudia 0echstein,TE1,*:A*.G+,=1 4 0123 01I6" /A"A7s8ating S";#E(/A"A)7\DA3UT1256/7white]4 "I"#E L=omenLLs BFFF Ceter Speed S8atingL4 I/ ;ear4 1564 2/S S"C# 3#2SE4 2/S S"C# >I#E7Lc:MCyS"C# ilesMs8ating'.htmL4 0123 01I6" /A"A7s8ating

S";#E(/A"A)7\DA3UT1256/7white]4 "I"#E L=omenLLs BFFF Ceter Speed S8atingL4 QA1 6ame 3ountry "ime4 QA1 1ecord9S";#E(/A"A)7 \>26".S";#E7italic >26".=EITS"7&old]4 I/ ;ear4 1564 2/S S"C# 3#2SE4 3ustomiEing 0123 1E021" 2utput with the S";#E7 2ption: 0123 1E021" S";#E(location-list) 7 \style-attribute 7 value]4 0123 1E021" /A"A 7 mysales S";#E(SEA/E1) 7 \DA3UT1256/ 7 green]4 /E>I6E Conth 9 T1250 S";#E(SEA/E1 32#5C6) 7 \DA3UT1256/ 7 &lue]4 D1EAU A>"E1 Conth 9 S5CCA1I-E S";#E(S5CCA1;) 7 \DA3UT1256/ 7 red]4 1D1EAU A>"E1 9 S5CCA1I-E S";#E(S5CCA1;) 7 \DA3UT1256/ 7 orange]4 E[: /A"A s8at4 I6>I#E cards /S/4 I605" 6ame :$(F. 3ountry $ ;ear 6umTold KK4 datalines4 #ydia S8o&li8o!a, 51S, +G*F, (, #ydia S8o&li8o!a, 51S, +G*A, A Uarin En8e, T/1, +GJF, +, Uarin En8e, T/1, +GJA, ( 3hrista 1othen&urger, T/1, +GJA, +, 3hrista 1othen&urger, T/1, +GJJ, + Donnie Dlair, 5SA, +GJJ, +, Donnie Dlair, 5SA, +GG(, ( Tunda 6ieman, T/1, +GG(, (, Donnie Dlair, 5SA, +GGA, ( 3laudia 0echstein, TE1, +GGA, +, Tunda 6ieman, T/1, +GGJ, + 3laudia 0echstein, TE1, +GGJ, +, 3atriona #eCay, 3A6, +GGJ, + 3laudia 0echstein, TE1, (FF(, (, 3atriona #eCay, 3A6, (FF(, + 4 2/S S"C# >I#E7Lc:MCyS"C# ilesMs8at.htmlL4 0123 1E021" /A"A 7 s8at nowindows4 32#5C6 6ame 3ountry 6umTold4 /E>I6E 6ame 9 T12504 /E>I6E 3ountry 9 T12504 "I"#E L2lympic =omenLLs L LSpeed S8atingL4 1564 2/S S"C# 3#2SE4 : S";#E7 option in 0123 statement4 2/S S"C# >I#E7Lc:MCyS"C# ilesMs8at(.htmL4 0123 1E021" /A"A 7 s8at 62=I6/2=S S";#E(32#5C6) 7 \DA3UT1256/ 7 white V5S" 7 center]4 32#5C6 6ame 3ountry 6umTold, S5C4 /E>I6E 6ame 9 T12504 /E>I6E 3ountry 9 T12504 "I"#E L2lympic =omenLLs L

LSpeed S8atingL4 1564 2/S S"C# 3#2SE4 : S";#E7 option in /E>I6E statement4 2/S S"C# >I#E7Lc:MCyS"C# ilesMs8at'.htmL4 0123 1E021" /A"A 7 s8at 62=I6/2=S4 32#5C6 6ame 3ountry 6umTold, S5C4 /E>I6E 6ame 9 T1250 S";#E(32#5C6) 7 \DA3UT1256/ 7 white V5S" 7 center]4 /E>I6E 3ountry 9 T12504 "I"#E L2lympic =omenLLs L LSpeed S8atingL4 1564 2/S S"C# 3#2SE4

3ustomiEing 0123 "AD5#A"E 2utput with the S";#E7 2ption 0123 "AD5#A"E /A"A 7 mysales S";#E 7 \DA3UT1256/ 7 yellow]4 "AD#E 3ity, Conth A##:\S";#E 7 \DA3UT1256/ 7 red]]4 3#ASS#EQ Conth 9 S";#E 7 \>21ET1256/ 7 green]4 >21 5SI6T /E>I6E >21CA": 0123 >21CA"4 QA#5E posneg #2= -Z F 7 ?red@ F-SITS 7 ?&lac8@4 QA1 Dalance 9 S";#E 7 \>21ET1256/ 7 posneg.]4 E[: 2/S S"C# >I#E7Lc:MCyS"C# ilesMresults.htmlL4 /A"A results4 I6>I#E cards /S/4 I605" 0lace 6ame :$(F. 3ountry :$+B. "ime4 cards4 +,Vochem 5ytdehaage, 6etherlands,')A.** (,/ere8 0arra, 5nited States,')).GJ ',Vens Doden, Termany,'J+.)' A,/mitry Shepel, 1ussia,'J+.JB B,U3 Doutiette, 5nited States,'J(.G) 4 0123 01I6" /A"A7results4 I/ 0lace4

"I"#E LCenLLs BFFFm Speed S8atingL4 "I"#E( L(FF( 2lympic 1esultsL4 1564 2/S S"C# 3#2SE4 2/S S"C# >I#E7Lc:MCyS"C# ilesMresults+.htmlL4 0123 >21CA"4 QA#5E rec F -Z ')J.)( 7LredL ')J.)( -Z 'J(.(F 7 LorangeL 'J(.(F - SITS 7 LwhiteL4 0123 01I6" /A"A7results4 I/ 0lace4 QA1 6ame 3ountry4 QA1 "ime9S";#E7\DA3UT1256/7rec.]4 "I"#E LCenLLs BFFFm Speed S8atingL4 "I"#E( L(FF( 2lympic 1esultsL4 1564 2/S S"C# 3#2SE9

C2 "#*R5H %Modifying and Combining S S. Data Sets& S*#: "he SE" statement with one SAS data set allows you to read and modi y the data. =ith two or more data sets, in addition to reading and modi ying the data, the SE" statement concatenates the data. Merge: =hen you want to match o&ser!ations rom one data set with o&ser!ations rom another, use the CE1TE statement in the /A"A step. 0y: i you are using &y statement in set or merge. so irst your data should &e sorted in order. data a4 input name$ pos4 cards4 a+ &( c' dA 4 data &4 input name$ ran84 cards4 a( c' dB 4 data E4 merge a &4 run4 data E+4 merge a &4 &y name4 run4 data d4 set a &4 run4 data d+4 set a &4 &y name4 run4 data 4 set a4 set &4 &y name4

run4 data one4 input id A D4 cards4 +F + ( (F ' A 'F B * 4 data two4 input id 34 cards4 +F F 'F + 4

data <+y+ <+yF <Fy+4 merge one(in7<) two(in7y)4 &y id4 i <7+ and y7+ then output <+y+4 i <7+ and y7F then output <+yF4 i <7F and y7+ then output <Fy+4 run4

/"D #*: the speciality o update is that, the Cissing !alues in the transaction data set do not o!erwrite e<isting !alues in the master data set.

/ata Caster4 in ile cards dlm7L L4 input I/ 6ACE$ "EAC$ =EITS"4 cards4 +++A +AA+ +)BF +GGA ('FA 4 sally &lue +(B sue green +AB joey red +JG mar8 yellow +*B joe red +)F

/ata transaction4 in ile cards dlm7L L4 input I/ 6ACE$ "EAC$ =EITS"4 cards4 +++A sally &lue ++G +GGA mar8 yellow +)A ('FA joe red +)F 4

/ata up4 update master tran4 &y id4 run4

3IRS#B)ariable and ! S#B)ariable: 2ther automatic !aria&les are a!aila&le only in special circumstances. "he >I1S".variable and #AS".variable automatic !aria&les are a!aila&le when you are using a D; statement in a /A"A step. "he >I1S".variable will ha!e a !alue o + when SAS is processing an o&ser!ation with the irst occurrence o a new !alue or that !aria&le and a !alue o F or the other o&ser!ations. "he #AS".variable will ha!e a !alue o + or an o&ser!ation with the last occurrence o a !alue or that !aria&le and the !alue F or the other o&ser!ations. *555555555555555555553IRS# ND ! S#555555559

/A"A A4 I605" 1ETI26 $ SA#E4 3A1/S4 621"S +FF 621"S ++F 621"S +(F 621"S +(B 621"S +'F 621"S +AF S25"S +FF S25"S ++F S25"S +(F S25"S +(' S25"S +'J S25"S +A( EAS" +FB EAS" ++B EAS" ++G EAS" +() EAS" +'F EAS" +'* =ES" +F( =ES" ++G =ES" +(* =ES" +'+ =ES" +'G =ES" +A' =ES" +AG 4 0123 S21" /A"A7A 25"7D4 D; 1ETI26 /ES3E6/I6T SA#E4 1564 /A"A 34

SE" D4 D; 1ETI264 1E"AI6 14 I> >I1S".1ETI26 "SE6 17F4 171++4 I> 1Z7B4 /120 14 1564 #R NS"$S*: the transposes procedure, turning o&ser!ations into !aria&les or !aria&les into o&ser!ations. In most cases, to con!ert o&ser!ations into !aria&les, you can use the ollowing statements /A"A E4 I605" S5DVE3" QISI" SD04 3A1/S4 +F+ + +*F +F+ ' +AF +F+ A +BF (F( + +A+ (F( ( +B+ (F( ' +*+ 4 : "R$C #R NS"$S* D # 04 variable-list4 ID variable4 V R variable-list4 7 old-data-set 25" 7 new-data-set4

0123 "1A6S02SE /A"A7E 25"7> 01E>I[7QISI"4 D; S5DVE3"4 1564

:--------------do loop---------------4 data in!est+4 do year7(FFF to (F+F4 capital+BFFF4 capital+(capital:.F)B)4 end4 run4 proc print 4run4

data in!est(4 do year7(FFF to (F+F4 capital+BFFF4 capital+(capital:.F)B)4 output4 end4 run4 proc print 4run4 data in!est'4 capital7F4 do year7+ to +F4 capital+BFFF4 do Ptr7+ to A4 capital+(capital:.F)B)4 end4 output4 end4 output4 run4 proc print 4run4 data in!estA4 capital7F4 do year7+ to +F4 capital+BFFF4 do Ptr7+ to A4 capital+(capital:.F)B)4 end4 end4 run4 proc print 4run4 data in!estB4 do year7+ to (B until(capitalY(BFFFF)4 capital+BFFF4 capital+(capital:.F)B)4 output4 end4 run4 proc print 4run4 data in!est*4 do year7+ to (B while(capitalZ(BFFFF)4 capital+BFFF4 capital+(capital:.F)B)4 output4 end4 run4 proc print 4run4

S SI1R "2 /A"A auto 4 I605" ma8e $ mpg rep)J weight oreign 4 3A1/S4 AC3 (( ' (G'F F AC3 +) ' ''BF F AC3 (( . (*AF F Audi +) B (J'F + Audi (' ' (F)F + DC= (B A (*BF + Duic8 (F ' '(BF F Duic8 +B A AFJF F Duic8 +J ' '*)F F Duic8 (* . (('F F Duic8 (F ' '(JF F Duic8 +* ' 'JJF F Duic8 +G ' 'AFF F 3ad. +A ' A''F F 3ad. +A ( 'GFF F 3ad. (+ ' A(GF F 3he!. (G ' (++F F 3he!. +* A '*GF F 3he!. (( ' '+JF F 3he!. (( ( '((F F 3he!. (A ( ()BF F 3he!. +G ' 'A'F F /atsun (' A (')F + /atsun 'B B (F(F + /atsun (A A ((JF + /atsun (+ A ()BF + 4 1564 "I"#E LSimple Qertical Dar 3hart L4 0123 3SA1" /A"A7auto4 QDA1 mpg ma8e4 1564 "I"#E LSimple Qertical Dar 3hart L4 "R$C C2 R# /A"A7auto4 hDA1 mpg ma8e4 R/N4 "I"#E LSimple Qertical Dar 3hart L4 0123 T3SA1" /A"A7auto4 QDA1 mpg4 1564 "I"#E LSimple Qertical Dar 3hart L4 0123 T3SA1" /A"A7auto4 SDA1 mpg4

1564 "I"#E LSimple Qertical Dar 3hart L4 0123 T3SA1" /A"A7auto4 QDA1 mpg9/IS31E"E4 1564 "I"#E LSimple Qertical Dar 3hart L4 0123 T3SA1" /A"A7auto4 SDA1 mpg9/IS31E"E4 1564 "I"#E LDar 3hart - 3ontrol 6um&er o DinsL4 0123 T3SA1"4 QDA1 mpg9#EQE#S7)4 1564 "I"#E L0ie 3hart with /iscreteL4 0123 T3SA1" /A"A7auto4 0IE rep)J9 /IS31E"E QA#5E7I6SI/E 0E13E6"7I6SI/E S#I3E725"SI/E4 1564 "I"#E LScatterplot - "wo Qaria&lesL4 0123 0#2" /A"A7auto4 0#2" mpg:weight7@:@ 4 1564

"I"#E LScatterplot - "wo Qaria&lesL4 0123 T0#2" /A"A7auto4 0#2" mpg:weight 4 1564

S;CD2#+ Q7circle 37&lac8 I7none4 S;CD2#( Q7star 37red I7none4 "I"#E LScatterplot - /i erent Sym&olsL4 0123 T0#2" /A"A7auto4 0#2" mpg:weight7 oreign4 1564 X5I"4 sum!ar speci ies the numeric !aria&le or sum or mean calculations

proc gchart data7s.d.s4

!&ar jo&code salary9sum!ar7salary type7mean4 run4 proc gchart data7s.d.s4 pie jo&code salary9sum!ar7salary type7sum4 ormat salary dollarJ.4 run4

proc gplot data7sashelp.class4 plot Age:Seight4 sym&ol c7red !7sPuare4 run4 Puit4 proc gplot data7sashelp.class4 plot name:Seight4 sym&ol c7red !7sPuare4 run4 Puit4 proc gplot data7sashelp.class4 plot name:Seight9cte<t7&lue4 sym&ol c7red !7star i7needle 4 run4 Puit4 :(i7join needle spline)4 :(!7sym&ol w7width c7color)4 goptions reset7glo&al4:to speci y graphic de!ice4 proc gplot data7sashelp.class4 plot (Age Seight =eight): 6ame9o!erlay ha<is7a<is+ !a<is7a<is( ca<is7red 4 a<is+ order7+ to J &y + 4 a<is( order7+ to (+F &y 'F4 sym&ol+ color7green interpol7spline width7( !alue7triangle height7' pointla&el7(h7+.B LRAgeL)4 sym&ol( color7&lue interpol7spline width7( !alue7circle height7' pointla&el7(h7+.B LRSeightL)4 sym&ol' color7red interpol7spline width7( !alue7sPuare height7' pointla&el7(h7+.B LR=eightL)4 run4 Puit4

C25J%macro& #he macro processor =hen you su&mit a standard SAS program, SAS compiles and then immediately e<ecutes it. Dut when you write a macro, there is an additional step. De ore SAS can compile and e<ecute your program, SAS must pass your macro statements to the macro processor which Hresol!esI your macros, generating standard SAS code E[: Macro statements

M CR$ "rocessor

Standard S S statements

Macros and macro variables SAS macro code consists o two &asic parts: macros and macro !aria&les. "he names o macro !aria&les are pre i<ed with an ampersand (O) while the names o macros are pre i<ed with a percent sign (N). !ocal versus global Cacro !aria&les can ha!e two 8inds o HscopeI.either local or glo&al. Tenerally, a macro !aria&le is local i it is de ined inside a macro. A macro !aria&le is generally glo&al i it is de ined in Hopen codeI which is e!erything outside a macro. ;ou can use a glo&al macro !aria&le anywhere in your program, &ut you can use a local macro !aria&le only inside its own macro. ( I you 8eep this in mind as you write your programs, you will a!oid two common errors: trying to use a local macro !aria&le outside its macro and accidentally creating local and glo&al macro !aria&les with the same name. #urning on the macro processor De ore you can use macros you must ha!e the CA312 system option turned on. "his option is usually turned on &y de ault, &ut may &e turned o , especially on main rames, &ecause SAS runs slightly aster when it doesn@t ha!e to &other with chec8ing or macros. I you are not sure whether the CA312 option is on, you can ind out &y su&mitting these statements: 0123 20"I26S 20"I26 7 CA3124 1564 E<: 20"I26S C01I6" S;CD2#TE6 C#2TI34 Nlet a7june4 Nlet &7july4 Nlet c7OaO&4 Nlet d7mayOa4 Nlet e7Oa.O&4 Nlet >7Oa..O&4 Nput Oa O& Oc Od Oe O 4

Nlet a7!ar name se< age height weight4 Nlet &7sashelp.class4 Nput class4 Nmacro class4 proc print data7O&4

Oa4 run4 Nmend class4 Nclass run4 N#E" A7 SE" SASSE#0.3#ASS4 /A"A S/4 OA4 1564

N#E" typ 7 Tinger4 /A"A lowersales4 I605" 3ustomerI/ $ K* Sale/ate CC//;;+F. K+) Qariety $ Xuantity4 I> Qariety 7WO typW4 /A"A#I6ES4 (AF= F(-F)-(FF' Tinger +(F (AF= F(-F)-(FF' 0rotea +JF 'B*= F(-FJ-(FF' Seliconia *F 'B*= F(-FJ-(FF' Anthurium 'FF +JJ1 F(-++-(FF' Tinger (A +JJ1 F(-++-(FF' Anthurium (A (AF= F(-+(-(FF' Seliconia AJ (AF= F(-+(-(FF' 0rotea AJ 'B*= F(-+(-(FF' Tinger (AF 4 0123 01I6" /A"A 7 lowersales4 >21CA" Sale/ate =21//A"E+J.4 "I"#E WSales o O typW4 1564 voiding macro errors "here@s no Puestion a&out it, macros can ma8e your head hurt. ;ou can a!oid the macro migraine &y de!eloping your program in a piecewise ashion. >irst, write your program in standard SAS code. "hen, when it@s &ug- ree, con!ert it to macro logic adding one eature at a time. "his modular approach to programming is always a good idea, &ut it@s critical with macros. 3reating Codular 3ode with Cacros: NCA312 macro-name4 macro-te$t NCE6/ macro-name4 E<: /A"A lowersale4 I605" 3ustomerI/ $ K* Sale/ate CC//;;+F. K+) Qariety $ Xuantity4 /A"A#I6ES4 (AF= F(-F)-(FF' Tinger +(F (AF= F(-F)-(FF' 0rotea +JF

'B*= F(-FJ-(FF' Seliconia *F 'B*= F(-FJ-(FF' Anthurium 'FF +JJ1 F(-++-(FF' Tinger (A +JJ1 F(-++-(FF' Anthurium (A (AF= F(-+(-(FF' Seliconia AJ (AF= F(-+(-(FF' 0rotea AJ 'B*= F(-+(-(FF' Tinger (AF 4 NCA312 sample4 0123 S21" /A"A 7 lowersale4 D; /ES3E6/I6T Xuantity4 0123 01I6" /A"A 7 lowersale (2DS 7 B)4 >21CA" Sale/ate =21//A"E+J.4 "I"#E L>i!e #argest SalesL4 NCE6/ sample4 Nsample 1564 dding "arameters to Macros: CA312 statement. Sere is one o the possi&le orms o the parameter-list. NCA312 macro-name 3!arameter-1( !arameter-2( . . . !arameter-n(4; macro-te$t NCE6/ macro-name4 =riting Cacros with 3onditional #ogic: NI> condition N"SE6 action4 NE#SE NI> condition N"SE6 action4 NE#SE action4 NI> condition N"SE6 N/24 SAS statements NE6/4 NCA312 select(customer7,sort!ar7)4 0123 S21" /A"A 7 lowersale 25" 7 salesout4 D; Osort!ar4 =SE1E 3ustomerI/ 7WOcustomerW4 0123 01I6" /A"A 7 salesout4 >21CA" Sale/ate =21//A"E+J.4 "I"#E+ W2rders or 3ustomer 6um&er OcustomerW4 "I"#E( WSorted &y Osort!arW4 NCE6/ select4 Nselect(customer 7 'B*=, sort!ar 7 Xuantity) Nselect(customer 7 (AF=, sort!ar 7 Qariety) 1564 utomatic macro variables E!ery time you in!o8e SAS, the macro processor automatically creates certain macro !aria&les. ;ou can use these !aria&les in your programs. "he most common automatic macro !aria&les are Variable name *+ample Description OS;S/A"E (GCA;F( the character !alue o the date that jo& or session &egan

OS;S/A; =ednesday the day o the wee8 that jo& or session &egan. E<: NCA312 dailyreports4 NI> OS;S/A; 7 tuesday N"SE6 N/24 0123 01I6" /A"A 7 lowersale4 >21CA" Sale/ate =21//A"E+J.4 "I"#E LConday 1eport: 3urrent >lower SalesL4 NE6/4 NCE6/ dailyreports4 Ndailyreports 1564

data ap4 input sale4 datalines4 +FFF ++FF +(FF +'FF +AFF +BFF 4 Nmacro setta<(ta<rate7)4 Nlet ta<rate 7 Nupcase(Ota<rate)4 Ni Ota<rate 7 L3SA6TEL Nthen Ndo4 data new4 set =21U.A04 i sale Y +FFF then ta< 7 .FB4 else ta< 7 .FJ4 run4 proc print data7new4 run4 Nend4 Nelse Ni Ota<rate 7 LSACEL Nthen Ndo4 data old4 set =21U.A04 ta< 7 .F'4 run4 proc print data7old4 run4 Nend4 Nmend setta<4 NSE""A[(ta<rate7L3SA6TEL) NSE""A[(ta<rate7LSACEL)

3A## S;C05": 3A## S;C05" ta8es a !alue rom a /A"A step and assigns it to a macro !aria&le. ;ou can then use this macro !aria&le in later steps. "o assign a !alue to a single macro !aria&le, you use 3A## S;C05" with this general orm: 3A## S;C05"(5macro-variable-name5 value)4

/A"A lowersales4 length !ariety $G4 I605" 3ustomerI/$ Sale/ate CC//;;+F. Qariety$ Xuantity4 ormat saledate ddmmyy+F.4 cards4 (AF= F(-F)-(FF' Tinger +(F (AF= F(-F)-(FF' 0rotea +JF 'B*= F(-FJ-(FF' Seliconia *F 'B*= F(-FJ-(FF' Anthurium 'FF +JJ1 F(-++-(FF' Tinger (A +JJ1 F(-++-(FF' Anthurium (A (AF= F(-+(-(FF' Seliconia AJ (AF= F(-+(-(FF' 0rotea AJ 'B*= F(-+(-(FF' Tinger (AF 4 0123 S21" /A"A 7 lowersales4 D; /ES3E6/I6T Xuantity4 run4 /A"A lowersales(4 SE" lowersales4 I> customerI/7L'B*=L "SE6 3A## S;C05"(WidW,customerI/)4 run4 0123 01I6" /A"A 7 lowersales(4 =SE1E 3ustomerI/ 7 WOidW4 >21CA" Sale/ate =21//A"E+J.4 "I"#E W3ustomer Oid Sad the Single #argest 2rderW4 1564 System options for debugging macros "hese i!e system options a ect the 8inds o messages SAS writes in your log. "he de ault settings appear in &old. M*RR$R ^ 62CE1121 when this option is on, SAS will issue a warning i you in!o8e a macro that SAS cannot ind. S*RR$R ^ 62SE1121 when this option is on, SAS will issue a warning i you use a macro !aria&le that SAS cannot ind. C#2TI3 ^ N$M!$1IC when this option is on, SAS prints in your log details a&out the e<ecution o macros. C01I6" ^ N$M"RIN# when this option is on, SAS prints in your log the standard SAS code generated &y macros. S;CD2#TE6 ^ N$S4M0$!1*N when this option is on, SAS prints in your log the !alues o macro !aria&les. 20"I26S C01I6" 62S;CD2#TE6 62C#2TI34

S SKSD!
proc sLl4 create ta&le a as select : rom sashelp.class4 Puit4 "R$C "RIN#4R/N4 proc sLl4 create ta&le a+ as select : rom sashelp.class where se< 7L>L and age 7M=4 title L0ersonnel /ataL4 Puit4 "R$C "RIN#4R/N4 proc sLl4 create ta&le wor8.new as select name,age,se< rom sashelp.class4 Puit4 "R$C "RIN#4R/N4 proc sLl4 create ta&le wor8.new+ as select name,age,se< rom sashelp.class where se< 7 L>L and age 7 M=4 title L0ersonnel /ataL4 Puit4 "R$C "RIN#4R/N4

:-------la&el-----4 proc sLl4 create ta&le wor8.& as select name la&el 7L nameL,se< la&el7LgenderL rom sashelp.class4 title L0ersonnel /ataL4 Puit4 "R$C "RIN#4R/N4

proc sLl4 create ta&le wor8.c as select name,age rom sashelp.class where age Y7 M?4 Puit4 "R$C "RIN#4R/N4 proc sLl4 /E#E"E rom a where age 7 MM4

Puit4 data s4 input status$ num4 cards4 a+ &( c' dA 4 data !4 input status$ ran4 cards4 a( c' dB 4 data 4 set s4 set !4 &y status4 run4 proc print4run4 proc sLl4 create ta&le h as select: rom s,! where s.status7!.status order &y status4 Puit4 proc print4run4 proc sLl4 create ta&le ss as select : rom s natural join !4 Puit4 "R$C "RIN#4R/N4 data -4 merge s(in7s) !(in7!)4 &y status4 I> s A6/ !4 run4 "R$C "RIN#4R/N4 data one4 input name$ pos4 cards4 a+ &( c' dA 4

data two4 input name$ ran84 cards4 a( c' dA 4

data &oth4 set one two4 run4 "R$C "RIN#4R/N4 proc sLl4 create ta&le &th+ as select: rom one outer union select: rom two4 Puit4 "R$C "RIN#4R/N4 proc sLl4 create ta&le &th as select: rom one outer union corr select: rom two4 Puit4 "R$C "RIN#4R/N4 data c4 input name$ pos4 cards4 a+ &( c' dA 4 data d4 input name$ ran84 cards4 a+ c' eB 4 proc sLl4 create ta&le 8 as select : rom c inner join d on c.name7d.name order &y name4 Puit4

"R$C "RIN#4R/N4

proc sLl4 create ta&le &th' as select : rom one natural join two4 Puit4 "R$C "RIN#4R/N4 data &oth4 set s !4 9:&y status4:9 run4 "R$C "RIN#4R/N4 data E+4 merge one two4 &y name4 run4 "R$C "RIN#4R/N4 data -(4 merge one(in7a) two(in7&)4 &y name4 I> a or &4 run4 "R$C "RIN#4R/N4 proc sLl4 create ta&le E' as select a.:,&.: rom one as a ull join two as & 26 a.name7&.name4 Puit4 "R$C "RIN#4R/N4 proc sLl4 create ta&le 2;E as select name,age rom wor8.c e<cept select name,age rom wor8.d4 Puit4 "R$C "RIN#4R/N4

proc sLl4 create ta&le dd (drop7height) as select : rom sashelp.class4 Puit4 "R$C "RIN#4R/N4 proc sLl4 create ta&le dsp+ as select : rom sashelp.class

where SE[7L>L 21/E1 D; ATE4 Puit4 "R$C "RIN#4R/N4

:----insert------4 proc sLl4 create ta&le E as select : rom sashelp.class4 insert into E !alues (LsachL,LCL,6N,J6,GJ)4 Puit4 "R$C "RIN#4R/N4 data Employees4 input KM Id6um $A. KJ #6ame $++. KMN >6ame $++. K6E Vo&3ode $'. K== Salary GB K=E 0hone $+(.4 datalines4 +J)* 3SI6 VA3U "A+ A(AFF (+(9BJJ-B*'A +++A T1EE6=A#/ VA6I3E CE' 'JFFF (+(9BJJ-+FG( +BB* 0E66I6T"26 CI3SAE# CE+ (GJ*F )+J9'J'-B*J+ +'BA 0A1UE1 CA1; >A' *BJFF G+A9ABB-('') ++'F =22/ /ED21AS 0"( '*B+A (+(9BJ)-FF+' 4 proc sLl4 alter ta&le employees modi y salary ormat7dollarJ. add position num ormat7NB4 drop phone4 Puit4 "R$C "RIN#4R/N4 data Employe4 input KM Id6um $A. KJ #6ame $++. KMN >6ame $++. K6E Vo&3ode $'. K== Salary GB K=E 0hone $+(.4 datalines4 +J)* 3SI6 VA3U "A+ A(AFF (+(9BJJ-B*'A +++A T1EE6=A#/ VA6I3E CE' 'JFFF (+(9BJJ-+FG( +BB* 0E66I6T"26 CI3SAE# CE+ (GJ*F )+J9'J'-B*J+ +'BA 0A1UE1 CA1; >A' *BJFF G+A9ABB-('') ++'F =22/ /ED21AS 0"( '*B+A (+(9BJ)-FF+' 4 proc sLl4 select : rom Employe4 update employe set salary7salary+ case when Vo&3ode7L"A+L "SE6 MFFF E#SE 6FFF E6/4 Puit4 "R$C "RIN#4R/N4

data sale4 input 2rderI/ K= 2rder/ate mmddyy+F. 2rder0rice 2rderXuantity 3ustomer6ame$4 ormat orderdate mmddyy+F.4 cards4 + +(9((9(FFB +*F ( Smith ( FJ9+F9(FFB +GF ( Vohns ' F)9+'9(FFB BFF B Daldw A F)9+B9(FFB A(F ( Smith B +(9((9(FFB +FF A =ood * +F9F(9(FFB J(F A Smith ) ++9F'9(FFB (FF ( Daldw 4 "R$C "RIN#4R/N4

proc sLl4 SE#E3" 3ustomer6ame, S5C(2rder0rice) AS T01I3E >12C Sale T1250 D; 3ustomer6ame 21/E1 D; M4 Puit4 proc sLl4 SE#E3" 3ustomer6ame, S5C(2rder0rice) AS T01I3E >12C Sale T1250 D; 3ustomer6ame 21/E1 D; 64 Puit4 proc sLl4 SE#E3" 3ustomer6ame, S5C(2rder0rice) AS T01I3E >12C Sale T1250 D; 3ustomer6ame SAQI6T gpriceYMFFF4 Puit4 proc sLl4 SE#E3" 3ustomer6ame, CEA6(2rder0rice) AS 21/E1CEA6 >12C Sale T1250 D; 3ustomer6ame 4 Puit4 proc sLl4 SE#E3" 3ustomer6ame,2rder0rice >12C Sale 21/E1 D; 3ustomer6ame 4 Puit4

SAS DASE 012T1ACCI6T

3reated &y S C2IN V*RM %S S 0ase certified&

You might also like