BookmarkSubscribeRSS Feed
CHW8
Calcite | Level 5

I am trying to convert an Access query into a SAS SQL.  I have struggled with converting the following SQL statement in Access to SAS:

IIf([LCLSTACK-BKY].Unit="OVEC-K Min" Or [LCLSTACK-BKY].Unit="OVEC-K Max" Or [LCLSTACK-BKY].Unit="OVEC-L Min" Or [LCLSTACK-BKY].Unit="OVEC-L Max" Or [CompanyOwner]="OMU" And [CounterParty]=" KU","PP",IIf([CompanyOwner]="MarketP","PU","PG")) AS MW_Type

 

What is the best way to code the above in SAS SQL?

2 REPLIES 2
LinusH
Tourmaline | Level 20

SAS is mainly ANSI SQL.

I'm  not very familiar with MS Access SQL, but is this conditional assignments?

Doesn't look the full query, I'm missing Select and From clauses.

To use conditional assignments, use the case - when - then - else construct.

Data never sleeps
Reeza
Super User
It's a case statement to create a new variable - break out the logic from your current code and convert it to a CASE statement. It looks like two conditions and an ELSE.

http://support.sas.com/documentation/cdl/en/proc/61895/HTML/default/viewer.htm#a002473682.htm

1. LCLSTACK-BKY].Unit="OVEC-K Min" Or [LCLSTACK-BKY].Unit="OVEC-K Max" Or [LCLSTACK-BKY].Unit="OVEC-L Min" Or [LCLSTACK-BKY].Unit="OVEC-L Max" Or [CompanyOwner]="OMU" And [CounterParty]=" KU"
-> "PP"
2. [CompanyOwner]="MarketP" -> "PU"
3. ELSE "PG"

You should verify the order of the conditions in that first condition as I'm not sure how the multiple OR with the AND would resolve. Make sure it meets your business needs.

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
  • 2 replies
  • 1111 views
  • 1 like
  • 3 in conversation