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

I had a case statement,

(case when t1.Date > '01Jan2016' then "NO"

        when t.1L = "N" then "NO"

       when  t.1L = "M" then "NO"

       else "YES" end) As "NewColumn"

 

I wanted to make a prompt so that when the program was run a person could pick what date they wanted to run the report off of instead of it always being '01Jan2016' or having to go in and changing the value of the date.

I created a prompt 'eligible' and then put it in the code so that it now read this:

case when t1.Date > &eligible then "NO"

        when t.1L = "N" then "NO"

       when  t.1L = "M" then "NO"

       else "YES" end) As "NewColumn"


Now it gives me the erorr: "

ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, *, **, +, -, /, <, <=, <>, =, >, >=, AND, EQ, EQT, GE, GET,"

 

It seems as though the macro worked because it says:

 

NOTE: Line generated by the macro variable "ELIGIBLE".

40 01Jan2017

 

Any help would be greatly appreciated.

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Your original program shouldn't work if your variable is actually a date, but if you want to make the new program look the same then you need to add quotes so that you are generating a valid string literal instead of just the text 01Jan2017.

 

case
  when t1.Date > "&eligible" then "NO"
  when t.1L = "N" then "NO"
  when  t.1L = "M" then "NO"
  else "YES" 
end As NewColumn

If your DATE variable is really a date and not a character string then you need to write your query using a date literal instead of a string literal.  So add the letter D after the closing quote so SAS knows you mean a date and not just a string literal.

case
  when t1.Date > "&eligible"d then "NO"
  when t.1L = "N" then "NO"
  when  t.1L = "M" then "NO"
  else "YES" 
end As NewColumn

 

View solution in original post

3 REPLIES 3
Tom
Super User Tom
Super User

Your original program shouldn't work if your variable is actually a date, but if you want to make the new program look the same then you need to add quotes so that you are generating a valid string literal instead of just the text 01Jan2017.

 

case
  when t1.Date > "&eligible" then "NO"
  when t.1L = "N" then "NO"
  when  t.1L = "M" then "NO"
  else "YES" 
end As NewColumn

If your DATE variable is really a date and not a character string then you need to write your query using a date literal instead of a string literal.  So add the letter D after the closing quote so SAS knows you mean a date and not just a string literal.

case
  when t1.Date > "&eligible"d then "NO"
  when t.1L = "N" then "NO"
  when  t.1L = "M" then "NO"
  else "YES" 
end As NewColumn

 

mmagnuson
Quartz | Level 8

Oh my goodness. I thought I had tried that but I guess I did the single quotes which didn't work

thank you!

 

Tom
Super User Tom
Super User

@mmagnuson wrote:

Oh my goodness. I thought I had tried that but I guess I did the single quotes which didn't work

thank you!

 


SAS does not evaluate macro triggers (& and %) inside of strings that use single quotes as the outer quotes.

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

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!

Register now

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1642 views
  • 0 likes
  • 2 in conversation