BookmarkSubscribeRSS Feed
saspert
Pyrite | Level 9

Hi,

I have issues trying to convert an MS access sql query to PROC SQL query. Appreciate any suggestions.

 

UPDATE [6 Cases w All Customer Detail] LEFT JOIN [1 EDW Customer Detail by ECID] ON ([6 Cases w All Customer Detail].Cycle=[1 EDW Customer Detail by ECID].Cycle) AND ([6 Cases w All Customer Detail].[ECI Number]=[1 EDW Customer Detail by ECID].[Eci Nb]) SET [6 Cases w All Customer Detail].[Case Use] = "No", [6 Cases w All Customer Detail].[Account Use] = "No", [6 Cases w All Customer Detail].[Account Use Reason] = "No Account Found"

WHERE ((([6 Cases w All Customer Detail].[Account Use]) Is Null) AND (([6 Cases w All Customer Detail].Cycle) Like [Enter Cycle]) AND (([1 EDW Customer Detail by ECID].[Eci Nb]) Is Null));

I have tried 3 different ways to convert the above query but am not able to do so -

1. PROC SQL create table having a left join

2. DATA A; update b c; by field names; run

3. proc sql update a set fields=values where

Thanks,

saspert


3 REPLIES 3
PGStats
Opal | Level 21

You can only update a single table with proc SQL. Bracketed names should be replaced with literal names. Something like

UPDATE X.'6 Cases w All Customer Detail'n as A

  SET 'Case Use'n = "No",

  'Account Use'n = "No",

  'Account Use Reason'n = "No Account Found"

WHERE

  'Account Use'n Is missing AND

  Cycle Like "Enter Cycle" AND

  'ECI Number'n not in

  (select  'Eci Nb'n

  from X.'1 EDW Customer Detail by ECID'n

  where Cycle = A.Cycle);

Might work, if X is the library where the tables reside.

If the update operation only involves DB tables, you might be better using your MS-Access query as a pass-through query.

PG

PG
saspert
Pyrite | Level 9

Hi PG,

Thanks for the tip. But why did you have the not in clause instead of the in clause. My attempt at this route has the  = clause because I need to join on the ECI Number to ECI Nb. But then it gives me errors because it is a 1 - many join.

So I will need to change the clause from = to not in?

PGStats
Opal | Level 21

In a left join, all records from the left side table will be present but when they are not matched with records from the right side table, all variables from the right side table will be missing. Thus, I assumed that your condition [1 EDW Customer Detail by ECID].[Eci Nb]) Is Null was equivalent to [Eci Nb] being absent from table [1 EDW Customer Detail by ECID] v.

PG

PG

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 3 replies
  • 1383 views
  • 0 likes
  • 2 in conversation