BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
VarunD
Obsidian | Level 7

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;

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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

View solution in original post

3 REPLIES 3
RW9
Diamond | Level 26 RW9
Diamond | Level 26

What does the log say, I am going to guess that:

MBR_DT_OF_BTH

Is not a numeric date variable, 

VarunD
Obsidian | Level 7

Deleting this for privacy. Thanks RW9 for spotting the error. 

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 881 views
  • 1 like
  • 2 in conversation