ds1
S_id | Sname | S_Subject |
1 | a | m |
2 | b | s |
3 | c | e |
ds2
S_id | Sname | S_subject |
1 | aa | s |
2 | b | s |
3 | ac | e |
i have two data sets one is old data set another one new data set . but have update values
one table like this , two data set upadate values highlight values
ds1_id | ds2_id | Ds1_name | ds2_name | ds1_S_subject | ds2_ |
1 | 1 | a | aa | m | s |
2 | 2 | b | b | s | s |
3 | 3 | c | ac | e | e |
another table is old values and update values
recds | s_id | S_name | S_subject |
old | 1 | a | m |
new | 1 | aa | s |
old | 3 | c | e |
new | 3 | ac | e |
anyone can help above problem?
Do you want both of the posted tables as result?
below both tables expacted output
ds1_id | ds2_id | Ds1_name | ds2_name | ds1_S_subject | ds2_S_SUBJECT |
1 | 1 | a | aa | m | s |
2 | 2 | b | b | s | s |
3 | 3 | c | ac | e | e |
second table
recds | s_id | S_name | S_subject |
old | 1 | a | m |
new | 1 | aa | s |
old | 3 | c | e |
new | 3 | ac | e |
Try this
data ds1;
input S_id Sname $ S_Subject $;
datalines;
1 a m
2 b s
3 c e
;
data ds2;
input S_id Sname $ S_subject $;
datalines;
1 aa s
2 b s
3 ac e
;
data want1;
format ds1_id ds2_id ds1_name ds2_name ds1_Subject ds2_Subject;
merge ds1(rename = (S_id = ds1_id Sname = ds1_name S_Subject = ds1_Subject))
ds2(rename = (S_id = ds2_id Sname = ds2_name S_Subject = ds2_Subject))
;
run;
data want2;
set want1;
if ds1_name ne ds2_name | ds1_Subject ne ds2_Subject then do;
recds = 'old';
Sname = ds1_name;
S_Subject = ds1_Subject;
output;
recds = 'new';
Sname = ds2_name;
S_Subject = ds2_Subject;
output;
end;
keep recds Sname S_Subject;
run;
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!
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.
Ready to level-up your skills? Choose your own adventure.