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

HI all,

I have two tables,

data test;

    infile datalines;

    input obs product $ quantity;

    datalines;

    1   A  2

    2   B  3

    3   C  5

    4   D  6

    ;

run;

data test2;

    infile datalines;

    input obs product $ quantity;

    datalines;

    1   A  5

    2   D  8

    ;

run;

I want to create a datasets as follows:

    1   A  5

    2   B  3

    3   C  5

    4   D  8

A and D gets updated value from test2? Is there way to achieve this using PROC SQL??

Thanks for the help in advance..

1 ACCEPTED SOLUTION

Accepted Solutions
slchen
Lapis Lazuli | Level 10


proc sql;
  update test as a
    set quantity=(select quantity from test2 b where a.product=b.product) where a.product in (select product from test2);
    quit;

or

data test;
  update test test2;
  by product;
  run;
 

View solution in original post

4 REPLIES 4
Reeza
Super User

Why SQL? This is easier in a data step.

stat_sas
Ammonite | Level 13

Try this.

proc sql;

select a.obs,a.product,COALESCE(b.quantity,a.quantity)

from test a left join test2 b

on a.product=b.product;

quit;

slchen
Lapis Lazuli | Level 10


proc sql;
  update test as a
    set quantity=(select quantity from test2 b where a.product=b.product) where a.product in (select product from test2);
    quit;

or

data test;
  update test test2;
  by product;
  run;
 

devnand
Obsidian | Level 7

thank you all for your suggestion

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 658 views
  • 4 likes
  • 4 in conversation