BookmarkSubscribeRSS Feed
JJP1
Pyrite | Level 9

Hi ,
please have a look on below sample data and please help

data source;
input num $1. amt sourcedate $10. loaddate $10.;
datalines;
1 32 19NOV2019 20NOV2019
2 45 19NOV2019 20NOV2019
3 89 18NOV2019 19NOV2019
;
run;
data target;
input num $1. amt sourcedate $10. loaddate $10.;
datalines;
1 32 19NOV2019 20NOV2019
2 45 19NOV2019 20NOV2019
3 89 18NOV2019 19NOV2019
;
run;

incorrect data is there in source dataset for date 18NOV2019
which got alreday loaded into target table.
so now the souce data will become as below.;

data source;
input num $1. amt sourcedate $10. loaddate $10.;
datalines;
1 32 19NOV2019 20NOV2019
2 45 19NOV2019 20NOV2019
3 54 18NOV2019 19NOV2019
;
run;

So target dataset now should show as below output(changed from 89 to 54) when i run below code;

data target;
input num $1. amt sourcedate $10. loaddate $10.;
datalines;
1 32 19NOV2019 20NOV2019
2 45 19NOV2019 20NOV2019
3 54 18NOV2019 19NOV2019
;
run;

I would want to do this using proc sql option.kindly help

4 REPLIES 4
Kurt_Bremser
Super User

In SQL, use update:

data target;
input num $1. amt sourcedate $10. loaddate $10.;
datalines;
1 32 19NOV2019 20NOV2019
2 45 19NOV2019 20NOV2019
3 89 18NOV2019 19NOV2019
;
run;

data source;
input num $1. amt sourcedate $10. loaddate $10.;
datalines;
1 32 19NOV2019 20NOV2019
2 45 19NOV2019 20NOV2019
3 54 18NOV2019 19NOV2019
;
run;

proc sql;
update target t
set amt = (select amt from source s where t.num = s.num and t.sourcedate = s.sourcedate)
;
quit;

proc print data=target noobs;
run;

Result:

num    amt    sourcedate    loaddate

 1      32    19NOV2019     20NOV2019
 2      45    19NOV2019     20NOV2019
 3      54    18NOV2019     19NOV2019
JJP1
Pyrite | Level 9

Thanks @Kurt_Bremser  .
Would you please suggest whether we can do it using proc sql (like left join ,right join,inner join) and get the same target table desired ?.
As i would want to see in this way just to see any possiblity .

Jagadishkatam
Amethyst | Level 16

Alternatively try the merge step to overwrite the target values in amt variable with source dataset amt variable

 

data target;
input num $1. amt sourcedate $10. loaddate $10.;
datalines;
1 32 19NOV2019 20NOV2019
2 45 19NOV2019 20NOV2019
3 89 18NOV2019 19NOV2019
;
run;

data source;
input num $1. amt sourcedate $10. loaddate $10.;
datalines;
1 32 19NOV2019 20NOV2019
2 45 19NOV2019 20NOV2019
3 54 18NOV2019 19NOV2019
;
run;

proc sort data=target;
by num sourcedate loaddate;
run;

proc sort data=source;
by num sourcedate loaddate;
run;

data want;
merge target(in=a) source(in=b);
by num sourcedate loaddate;
run;
Thanks,
Jag

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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