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;
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
What does the log say, I am going to guess that:
MBR_DT_OF_BTH
Is not a numeric date variable,
Deleting this for privacy. Thanks RW9 for spotting the error.
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
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.