BookmarkSubscribeRSS Feed
BigVinnie
Calcite | Level 5

Hello Everybody,

 

I am completely new to the world of SAS and I need to translate a SAS case stateemnt to SQL.

 

here is the line of code

WHEN (INDEX(UPCASE(SALES_STATUS), 'FORM RECEIVED')) >= 1 THEN 'Form Received'

 

a) In English what is this line of code doing?

b) how would I write this in SQL?

 

I can't seem to get the functions or syntax to work in SQL.

 

Any help would be much appreciated.

 

Kind Regards

 

Vinnie

4 REPLIES 4
PeterClemmensen
Tourmaline | Level 20

Welcome to the SAS communities. The questions are better answered reversed:

 

b) The code in PROC SQL goes something like this

 

proc sql;
   create table want as
   select (case 
             when (index(upcase(sales_status), 'FORM RECEIVED')) >= 1 then 'Form Received' 
           end) as newvar
   from have;
quit;

a) The code looks for the string "FORM RECEIVED" (not considering case) in the variable sales_status. If the string is present, the variable newvar will have the value "Form Received". 

BigVinnie
Calcite | Level 5

Thank you for your help

Kurt_Bremser
Super User

If you need to translate this to a non-SAS SQL system, you will probably have to replace index() and upcase() with functions available there. The rest of the code is standard SQL and should need to adaptation.

Tom
Super User Tom
Super User

Can you show more of the full code that you are trying to translate?

I am confused because the snippet that you did show looks like it is part of an SQL CASE expression.

Why would you need to translate SQL to SQL?

 

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 1348 views
  • 1 like
  • 4 in conversation