- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I am trying to calculate age for Missing values as per the following step and getting syntax error.
What am I doing wrong here :
Varun
PROC SQL;
CREATE TABLE Employee2 AS
SELECT DISTINCT t1.Table1,
variable1,
variable2,
case when variable1 NE . and variable2 LT 18.
then '17 & Younger'
case when variable1 NE . and variable2 GT 18.
then '18 & Older'
case when variable1 EQ .
then YRDIF(Today(),variable2,'ACT/ACT'))
else 'Not defined'
end as Age
else 'Not defined'
end as Age
FROM Table2 t1
;
QUIT;
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
That shows where you issue is, your case when statement is invalid.
Case statements have two forms:
case when <condition> then <value> when <condition> then <value> else <value> end
Or:
case <variable> when <condition> then <value> when <condition> then <value> else <value> end
So:
case when MBR_AGE NE . and MBR_AGE LT 18. then '17 & Younger' <--- valid case when MBR_AGE NE . and MBR_AGE GT 18. then '18 & Older' <--- invalid, extra "case" case when MBR_AGE EQ . then YRDIF(Today(),MBR_DT_OF_BTH,'ACT/ACT')) <---- invalid extra 'case' else 'Not defined' <---valid only when above corrected end as Age else 'Not defined' <--- invalid, no case defined. end as Age
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
What does the log say, I am going to guess that:
MBR_DT_OF_BTH
Is not a numeric date variable,
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Deleting this for privacy. Thanks RW9 for spotting the error.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
That shows where you issue is, your case when statement is invalid.
Case statements have two forms:
case when <condition> then <value> when <condition> then <value> else <value> end
Or:
case <variable> when <condition> then <value> when <condition> then <value> else <value> end
So:
case when MBR_AGE NE . and MBR_AGE LT 18. then '17 & Younger' <--- valid case when MBR_AGE NE . and MBR_AGE GT 18. then '18 & Older' <--- invalid, extra "case" case when MBR_AGE EQ . then YRDIF(Today(),MBR_DT_OF_BTH,'ACT/ACT')) <---- invalid extra 'case' else 'Not defined' <---valid only when above corrected end as Age else 'Not defined' <--- invalid, no case defined. end as Age