Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Error when creating age group

mem_age_tmp:

LOAD

     MEM#,

     if(Age >= 18, '>=18',

     if(Age <= 17 and Age >= 0, '0-17')) as Age_Group

Resident mem;

I tried to create a couple of Age_Group using the above code but I am getting an error when I run it.

What is wrong with the above code? Any help would be greatly appreciated.

Thanks.

1 Solution

Accepted Solutions
Not applicable
Author

Hi, I see the error now, it seem obvious but is hard to see, the last greater or equal symbol is written as "=>" when the correct notation should be ">=".

Regards

View solution in original post

8 Replies
Not applicable
Author

Hi, could you be more specific about the error thrown by QlikView, because your syntaxis looks alright to me. Also, when I create age groups, I always use the intervalmatch function within the script, or a calculated dimension using the class function within the GUI, I suggest to use one of those, depending on your requirement, since they are much easier to handle and mantain.

Regards

Anonymous
Not applicable
Author

Hi.

I think you don't have the second "if" statement complete.

Qlikiview if is a ternary expression, and the third parameter is mandatory.

I believe this will load:

LOAD

     MEM#,

     if(Age >= 18, '>=18',

     if(Age <= 17 and Age >= 0, '0-17','Other?')) as Age_Group

Resident mem;

Even if the "else" does not exist.

Hope it helps,

Miguel Catalão

Not applicable
Author

Hi, actually the third parameter is not mandatory, QV will evaluate to a null value in the case that a value does not meet the condition and the else parameter was not provided, but it will never be the source of a script error.

Regards

Anonymous
Not applicable
Author

Oh, you are right, just tested it.

I also tested the full load expression with the chained "if"'s and it seems ok.

Can you debug the code and see where it stops?

Not applicable
Author

Hi again, is QV returning a general script error??, because sometimes I happen to write my code ok, and QV seems to find a unexistent error, what I do to solve is close QV completely and open it again.

Hope tis helps.

Regards

Anonymous
Not applicable
Author

Hi Ivan,

The error message is

     Error in expression:l')' expected

     mem_age_tmp:

     LOAD

          MEM#,

     if(Age >=18,'>=18',

     if(Age <= 17 and Age=>0,'0-17')) as Age_Group

     Resident mem

As an FYI, Age is calculated in a load that ran previous to this. The table is calls mem. I listed the code below:

mem:

LOAD

MEM#,

//MEM#,

//MEM# as Pharm_MEM#,

//MEM# as Med_MEM#,

    NAME,

     DOB,

     Age('12/31/2011',DOB) as Age,

     [MED MONTHS],

     [PHAR MONTHS],

     [RAW ACG],

     [PRE COST],

     [PROB INP],

     AGGREGATE,

     ADDRESS,

     CITY,

     STATE,

     [ZIP CODE]

FROM

Data\Dimensions\mem.qvd

(qvd);

Not applicable
Author

Hi, I see the error now, it seem obvious but is hard to see, the last greater or equal symbol is written as "=>" when the correct notation should be ">=".

Regards

Anonymous
Not applicable
Author

Hi Ivan,

That was the problem. Thank you!