DATA Step, Macro, Functions and more

Convert Access query to SAS SQL

Reply
Occasional Learner
Posts: 1

Convert Access query to SAS SQL

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?

Super User
Posts: 5,260

Re: Convert Access query to SAS SQL

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
Super User
Posts: 17,912

Re: Convert Access query to SAS SQL

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.
Ask a Question
Discussion stats
  • 2 replies
  • 206 views
  • 1 like
  • 3 in conversation