BookmarkSubscribeRSS Feed
amyk
Fluorite | Level 6

Hi All,

 

I hope you can help me. I am trying to create a database depending on varies criteria and I am trying to find a way to pull it all together.

 

I have, say database1 with values and depending on if a variable received from another source (File1) exists then use values from databases2 that have the variable if exists from File1 . I have identified if the variable exists and now I am trying to set that value from database2 to replace value from database1.

 

6 REPLIES 6
Reeza
Super User
If you provide some sample data, fake is totally fine, that illustrates your problem with data you're more likley to get a solution.

There's more than likely a way to do this, but a vague general question = a vague general response. If you're just looking for ideas/directions, UPDATE from SQL or data step may be what you need, or you may need to do a join/merge.
amyk
Fluorite | Level 6

That is the thing I don't know where to start to join things together.

 

I will try to mock up something that maybe helps better to explain what I am trying to do.

 

say in database1 if have V_W = "Hello" and if File1 has Var1 = "PPO"

 

then in database2 where Var1=PPO  update database1 with value in database2.

 

I am struggling with how would I do that.

 

 

Reeza
Super User
Don't worry about the code or technicalities at this point, create examples of what you have to start with and what you want. Think of as many variations and edge cases as possible.

Honestly, if you don't know that ahead of time it's 10x harder and longer to get the code right.
amyk
Fluorite | Level 6

 

Create Table OptionSet

as 

select a, b, c

if a.V_W = ""  or C.V_AWZ = "Y" then a.V_W = b.V_W end;

if a.V_X = ""   or C.V_BWZ = "Y" then a.V_X = b.V_X end;

if a.V_Y = ""   or C.V_CWZ = "Y" then a.V_Y = b.V_Y end;

if a.V_Z = ""   or C.V_DWZ = "Y" then a.V_Z = b.V_Z end;

quit. 

 

 

Patrick
Opal | Level 21

@amyk 

I believe it's may be best to start with data. Could you please provide sample data which showcase what you have and then tell us how the desired result should look like.

About terminology: I'm a bit confused what you call "database" and what you call "file". Is database a table in a database and file a SAS table? Or is it something else?

ballardw
Super User

@amyk wrote:

 

Create Table OptionSet

as 

select a, b, c

if a.V_W = ""  or C.V_AWZ = "Y" then a.V_W = b.V_W end;

if a.V_X = ""   or C.V_BWZ = "Y" then a.V_X = b.V_X end;

if a.V_Y = ""   or C.V_CWZ = "Y" then a.V_Y = b.V_Y end;

if a.V_Z = ""   or C.V_DWZ = "Y" then a.V_Z = b.V_Z end;

quit. 

 

 


Really recommend following @Reeza's suggestion of data examples. Your pseudocode above references values of multiple variable from multiple tables, A and C, without any consideration of how A and C should relate to ensure the correct values are considered.

Also multiple basically identical comparison/results often is an indication that maybe the data could be better structured

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 742 views
  • 2 likes
  • 4 in conversation