SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
RandomUserFS
Calcite | Level 5

Hello everybody,

 

I'm not sure how to convert the following Oracle SQL syntax with DECODE function in to Proc SQL syntax within SAS.

Your assistance would be greatly appreciated.

 

DECODE(( con.AREA_CODE ),NULL,NULL,'('||( con.AREA_CODE )||') ')||( con.CONTACT_NUMBER )||DECODE(( con.EXTENSION ),NULL,NULL,' ext.'||( con.EXTENSION )) as Ind_Home_Phone ,

 

 

Thanks

1 REPLY 1
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Decode is just another way of doing a case when statement.

 

So <variable is your variable, code is the short term you might have, and decode is the long term is the long value you want:

decode(<variable>,<code>,<decode>,[<code>,<decode>])

case <variable> when <code> then <decode>
                when <code> then <decode>
                else <value> end as <new_variable>

case when <condition> then <decode>
     when <condition> then <decode>
     else <value> end as <new_variable>

So if you had:

xyz=decode(old_var,"a","something","b","else")

The equivalent would be:

case old_var when "a" then "something"
                      when "b" then "else"
                      else "" end as xyz

I used the first method of case here, but either works.

 

 

 

 

 

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 1 reply
  • 15968 views
  • 0 likes
  • 2 in conversation