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

SELECT IIf([Group]="07M","GWB","EIA") & IIf(Left([ISSUE_DATE],4) <"2003","2003",Left([ISSUE_DATE],4)) AS IY

 

IY

EIA2003
EIA2004
EIA2005
EIA2006
EIA2007
EIA2008
EIA2009
EIA2010
EIA2011
EIA2012
EIA2013
EIA2014
EIA2015
EIA2016
EIA2017
EIA2018
EIA2019
EIA2020
GWB2016
GWB2017
GWB2018
GWB2019
GWB2020

 

CASE WHEN EPLAN.Group = "07M" THEN "GWB"
5665 ELSE "EIA"
5666 AND WHEN YEAR(ISSUE_DATE) < 2003 THEN 2003
                               ____
22
76

ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, (, *, **, +, -, /, <, <=, <>, =, >, >=, ?, AND, BETWEEN,
CONTAINS, EQ, EQT, GE, GET, GT, GTT, LE, LET, LIKE, LT, LTT, NE, NET, OR, ^=, |, ||, ~=.

ERROR 76-322: Syntax error, statement will be ignored.

5667 ELSE YEAR(ISSUE_DATE)
5668 END AS IY

 

I'm in need of some assistance. At the very top of this post is the SQL code that I'm trying to replicate. The IY field that's created is the column that follows and the SAS code that I'm running comes last. I'm not sure how to create this nested if formula using the CASE WHEN function. 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

CASE when substr(year,1,4) < 2003 then 2003
else substr(issue_date, 1, 4) end as yearPortion,
CASE WHEN EPLAN.Group = "07M" THEN catt("GWB", calculated yearPortion)
ELSE catt("EIA", calculated yearPortion)
END as IY

View solution in original post

3 REPLIES 3
Reeza
Super User
What is the type of your variable ISSUE_DATE?
If it's not numeric with a date format, then it's not a SAS date and you need to sue text functions similar to what you did in Excel.

In the future, please show the code you actually submitted, not just the Excel code or log. It's possible to do this in one step but

CASE when substr(year,1,4) < 2003 then 2003
else substr(issue_date, 1, 4) end as yearPortion,
CASE WHEN EPLAN.Group = "07M" THEN catt("GWB", yearPortion)
ELSE catt("EIA", yearPortion)
END as IY

Your CASE syntax is incorrect.


izzytetteh24
Calcite | Level 5
I'm getting an error that says yearPortion was a column not found in the contributing tables.
"ERROR: The following columns were not found in the contributing tables: yearPortion."
Reeza
Super User

CASE when substr(year,1,4) < 2003 then 2003
else substr(issue_date, 1, 4) end as yearPortion,
CASE WHEN EPLAN.Group = "07M" THEN catt("GWB", calculated yearPortion)
ELSE catt("EIA", calculated yearPortion)
END as IY

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 1076 views
  • 0 likes
  • 2 in conversation