BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Xamius32
Calcite | Level 5

Lets say I want to update table A based on a column in table B. Table B will have a list of games (like A, B, C, D) and if those games are in table A, I want to decrease a certain value. if I do

proc sql ;

  update A set value=value-1

  where game in (select game from B)

  ;

quit;


if dataset B has a game listed more than once, will the value decrease more than once? IE if its listed twice, the value in dataset A will decrease by 2.

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

You could make it execute by adding the UPDATE_POLICY=NONE but why?  If you leave it coded the way it is the update will happen for every row as every value of GAME in dataset A is by definition in dataset A.

View solution in original post

4 REPLIES 4
Xamius32
Calcite | Level 5

and one more question, if I wanted to do the same thing, but using simply another column in table A, is that possible? When I try it by changing B to A, it says sql cant use the table it is updating to update.

Tom
Super User Tom
Super User

You could make it execute by adding the UPDATE_POLICY=NONE but why?  If you leave it coded the way it is the update will happen for every row as every value of GAME in dataset A is by definition in dataset A.

Xamius32
Calcite | Level 5

I realize by you saying that I am looking at this in the wrong way in terms of my goals. Anyways, thx for the help.

Tom
Super User Tom
Super User

No.  It will process each row in A and decide whether that GAME exists in B, if it does it will execute the update.

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