declare

SAS Array Made Easy - Syntax and Workout Example



Sharing buttons:

in this video I will explain your salary

its syntax and a workout example you

will learn how to define it how to use

it and how does it work how does it help

to make sure that you understand its

usage in a proper way I am going to

explain you everything through example

let me show you an example the data goes

like this here you have 40 agents 40

salesmen and you have their sales figure

that how much they have sold in each

month so in January salesmen one has

sold 52 item 93 item like that now the

task is fairly complicated in this case

the task goes like this find the month

for each salesmen Vinnie sold maximum so

if you look at this salesman had sold

maximum and that you have to figure out

only between July 15 to do Nick Steen so

your whole period is only this to this

so you have to find out in which month

he has done maximum if you look at this

person he has done maximum in February

16 you have also make need to make a

note of the maximum month if the maximum

month for any reason is in two period is

same take the first period so

essentially if at all you are talking of

only three period 165 165 then take July

15 as the first month when the maximum

age occurred if it is same in any two of

the month the third is you have to find

four months average prior to the maximum

sale along with the period so for this

case you will say the four month average

prior average is actually fifty-seven

point two five and you will say it has

occurred between October 15 to Jan 16

and you need to do the same thing for

post period you need to say it has

occurred between mar 16 2016 at the

average is 150 3.75 and then you need to

calculate ratio of post by pre

so if you look at tasks while it is a

fairly complicated what I have done here

I imported this data in SAS that process

anyways very much same as the way you

import anywhere and here I have the data

let me show you how does my data look

like obviously very much the way it is

in Excel so you have salesmen and their

spent their sales in these periods now

let's go ahead and let me show you a

lengthy way by which I can achieve this

and then you will be able to appreciate

the usage of area even more so what I

have done look at I can do any iterative

way so what I can do maximum is here and

then I can say focused is more than July

make August at maximum and then go next

if September is more the maximum of

these period make September at maximum

and make a note of September so look at

what I am doing here I have done it this

way max figure July 15 maximum July 15

decision text if agostic more than max

figure max figure takes the value of

August 15 and Max ma takes the figure of

August 15 and here it is if look at here

again it is if so it is not else so a

brick thing will get executed and you

can keep writing it and that's how you

can find when it is the maximum month is

occurring I can show you it works

however it will work only for July

August and September let me show it to

you see if I am going to run it it will

find out between July August and

September which is the best month and it

will also find the month name so look at

it has found out that max figure is 166

and max month each one saves September

15 and look at its the case you know if

you are talking of only these three

period September 15 166 in case of the

second record it will save 165 do

recover same take the first one and that

is why if you look at force first second

one it says 165 is max figure and July

15 when it has occurred so it is working

but look at what will happen you

end up writing this you know for each

and every month and then you have to

find first for last for you actually it

will become a lengthy code you have to

find even the period so let me show you

a smart way of doing that

a smart way is actually using the SAS

array and let me show you harder SAS

array makes it just a three line code so

what I have done here here I define SAS

area so first array each amount and look

at January 15 February 15 March 15 these

are actually the variable name which it

is taking look at I haven't put any

comma here and next I defined actually a

text array where you look at July fridge

Jan 15 and there is no comma in between

and these are you know giant to December

24 sides this is also 24 side but this

will contain the value of variable and

this will contain just the text then I

define max figure July max July 15 7

understand one thing amount one will

refer this amount to will refer this

amount three value for this because I

need to just figure out between these

two this period I am starting from here

so this is say burn because if you look

at one two three four five six similarly

this is six so seven eight nine ten

eleven twelve so if I am going from 10

to 18 this is where I need to find

maximum and that I am able to achieve by

just one line eight to 18 if amount eyes

more than max figure max figure takes

amount I max month month I and Max

position whatever is the position of I

and then look at my pre and post how

easy it becomes I know max position in

this case if you look at the first

record the max position will actually

come at 14th position so what you need

to do in 11 12 13 take the average of

these four and you can take the name

also like that

10 to 13 it will give you the value and

that is what I have done here so if you

look at pre average - 4 - 3 - 2 - 1 and

it will work for each and every record

and pre period you need just the minus 4

and minus 1 position because you like to

say October 15 - Jan 16 and for post

what you would like to say again you

will take the 4 takes divided sum and

divide by 4 and you will say period plus

1 2 . + 4 that will give you may march

16 - 16 that is what I have done here

plus 1 2 plus 4 and then pre post ratio

anyways same and let me show you it

works exactly in a very simple step it

works

so look at it found out that maximum

month has occurred February 16

Maxpedition is 14 pre period is October

15 - generally 16 and post period is

March 16 to Jules June 16 Everage 57 153

and two-point so everything exactly the

way we are doing it has created and for

each and every record and you are able

to do that by just a small code so I

hope that has explained you that how a

complicated task became fairly simple by

use of sassari

the code is available to download look

in the resource area there is a

hyperlink which will take you to the

sassy record you can download thank you

you should subscribe to this channel so

that you remain updated whenever I post

new video