www OASUS ca You deserve ARRAYs How to


















- Slides: 18
www. OASUS. ca You deserve ARRAYs! How to be more efficient using SAS® By: Kate Burnett-Isaacs Presented at SAS Global Forum 2015 “Come out of the desert of ignorance to the OASUS of knowledge”
Introduction www. OASUS. ca • An array is a group of related variables defined in a DATA step • Arrays are extremely useful when a repetitive process, such as a calculation, transformation or function, needs to be applied to a large set of variables • An array enables the programmer to set a list of variables once and then refer this list, or elements within the list, any number of times within a single DATA step
www. OASUS. ca Establishing The Array • We define an array in an ARRAY statement within the DATA step by the keyword ‘array’ : array_name {N} variable 1 … variable. N; • Array name: array_name • Length of the array: {N} or {*} • Variables or array elements that it will contain: variable 1 … variable. N • All array elements must be character or numeric
www. OASUS. ca Using The Array • The number in the braces indicates the corresponding element in the array • To refer variable 2: array_name {2}; • To apply a repetitive process to a large set of variables, use the DO loop: do i=1 to dim(array_name); array_name {i}=i; end; • Use all of the array elements together in the calculation of the sum or mean with OF operator: Total=sum(of array_name {*});
www. OASUS. ca Example • You are an employer, whose employees took a week long SAS course • If they were absent, no grade is present • To reward participation, each employee gets 2% of their weekly earnings for every day they attend the course • You want to show your employees how much they made each day of the course and what their total weekly salary will be at the end of the week long course
www. OASUS. ca Example Dataset
www. OASUS. ca Example with IF-ELSE Statement data No_Arrays; set SAS_scores; if NOT MISSING(Monday) then Bns. Mon=(Wkearn*0. 02); else Bns. Mon=0; if NOT MISSING(Tuesday) then Bns. Tues=(Wkearn*0. 02); else Bns. Tues=0; if NOT MISSING(Wednesday) then Bns. Wed=(Wkearn*0. 02); else Bns. Wed=0; if NOT MISSING(Thursday) then Bns. Thurs=(Wkearn*0. 02); else Bns. Thurs=0; if NOT MISSING(Friday) then Bns. Fri=(Wkearn*0. 02); else Bns. Fri=0; fnlearn=wkearn+sum(Bns. Mon, Bns. Tues, Bns. Wed, Bns. Thurs, Bns. Fri); keep Name Bns. Mon Bns. Tues ab. Wed Bns. Thurs Bns. Fri fnlearn; run;
www. OASUS. ca Example with Arrays data Using_Arrays; set SAS_scores; array_day {*} Monday Tuesday Wednesday Thursday Friday; array bonus {*} Bns. Mon Bns. Tues Bns. Wed Bns. Thurs Bns. Fri; do i=1 to dim(array_day); if NOT MISSING(array_day {i}) then bonus{i}=Wkearn*(0. 02); else bonus {i}=0; end; fnlearn=(wkearn+sum(of bonus {*})); keep Name Bns. Mon Bns. Tues ab. Wed Bns. Thurs Bns. Fri fnlearn; run;
www. OASUS. ca Results
Conclusion www. OASUS. ca • Arrays can easily scale with the size of the program and the data, the time and effort saved will also increase accordingly • An array is a very useful tool when repetitively processing large sets of variables. • Arrays allow repetitive code to be more efficiently executed and less prone to coding mistakes. • Use arrays and in no time you will receive your raise!
www. OASUS. ca The SAS Global Forum Experience “Come out of the desert of ignorance to the OASUS of knowledge”
Process www. OASUS. ca Idea Session Choice Application Process Presenting
www. OASUS. ca How to Choose a Paper Topic • What you found challenging in your own SAS experience • What you would like to learn more about • Some code, techniques or process that you have created which is rather unique
www. OASUS. ca • • Session Choice Quick Tip Breakout Session Poster Table Talk
www. OASUS. ca • • Application Process Apply on SAS Global Forum website Abstract Draft paper Catchy title
www. OASUS. ca • • Presenting Minimal text or code on the slides At most, one slide per minute Leave time for questions Know your audience
www. OASUS. ca At SAS Global Forum • Experience as much as you can • Choose the presentations you attend wisely • Network
www. OASUS. ca Questions? October 30, 2020 First & last name Company name 18


















