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

Hi,

 

As part of my programming, I have a query which updates a TARGET table with values from the SOURCE table.

 

proc sql;
update SCHEMA.TARGET as u
set &COLUMN_NAME. =(select value from &COLUMN_NAME. as n
where strip(u.ID)=strip(n.ID))
;quit;

COLUMN_NAME is an attribute on TARGET table, it is a table as well. I am trying to update the column with values from the corresponding table. The variable values will be changed dynamically.

 

Can you please advise how to achieve this using data steps, this approach seems to be a bit slow.

 

Thank you.

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User
proc sort data=&column_name.;
by id;
run;

proc sort data=schema.target;
by id;
run;

data schema.target_new;
merge
  schema.target (in=orig)
  &column_name. (in=update keep=id value)
;
by id;
if orig;
if update then &column_name. = value;
drop value;
run;

Once you have verified the result, remove schema.target and rename schema.target_new to schema.target.

View solution in original post

3 REPLIES 3
PeterClemmensen
Tourmaline | Level 20

What do you mean by "COLUMN_NAME is an attribute on TARGET table"?

 

Also, can you provide some sample data for us to work with, that resembles your actual data? Makes it much easier to help you.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Post test data of both datasets in the form of a datastep:

https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat...

 

And show what you expect from them.

 

I am pretty certain however that there is a much better method than the update you present here, a simple merge on ID would be far more efficient.

Kurt_Bremser
Super User
proc sort data=&column_name.;
by id;
run;

proc sort data=schema.target;
by id;
run;

data schema.target_new;
merge
  schema.target (in=orig)
  &column_name. (in=update keep=id value)
;
by id;
if orig;
if update then &column_name. = value;
drop value;
run;

Once you have verified the result, remove schema.target and rename schema.target_new to schema.target.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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