Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
I have AGE filed in my table. I want convert it into Age group.
Age
21
14
15
19
25
32
I want covert like if AGE= (1-20) Young, (21-30)Middle. (31-40)Upper
Hi,
try with simple if else statement in script
try like
if(age>0 and age<21,'Young',if(age>21 and age<31,'Middle',if(age>30 and age<41,'Upper'))) as age_group
or
if(age>0 and age<21,'Young',if(age>21 and age<31,'Middle','Upper')) as age_group
Regards
Prashant Sangle
Hi,
Please try this.
I included logic for Age > 40 as well. You can remove if it is not needed.
Data:
LOAD *,if(Age<=20 ,'Young',
if(Age>=21 and Age<=30 ,'Middle',
if(Age>=31 and Age<=40 ,'Upper','Other'
))) as [Age Group];
LOAD * INLINE [
Age
1
11
14
18
21
14
15
19
25
32
42
54
65
88
100];
Can possibly also use IntervalMatch:
Age: Load * Inline [ Age 21 14 15 19 25 32 ]; AgeInterval: Load * Inline [ Min, Max, AgeGroup 1, 20, Young 21, 30, Middle 31, 99, Upper ]; Inner Join IntervalMatch (Age) Load Min, Max Resident AgeInterval; Left Join (Age) Load Age, AgeGroup Resident AgeInterval; Drop Table AgeInterval;