BookmarkSubscribeRSS Feed
Jhunait
Calcite | Level 5
Hi all! New guy trying to code in SAS here. I have this task combining 2 dataset. Shown below are the valid scenarios and invalid. All help is acceptable! Thanks!

Scenario 1 - Valid
File1
VarA VarB. VarC
A1. R1. C1. - write output file
A2. R1. C2. - write output file

File2
A1. R1. C1
A2. R1. C2

Scenario 2 - Invalid
File1
A1. R1. C1. - no action taken
A2. R1. C2. - no action taken

File2
A1. R1. C1
A2. R1. C2
A3. R1. C3

Scenario 3 - Invalid
File1
A1. R1. C1 - no action taken
A2. R1. C2 - no action taken

File2
A1. R1. C1
A2. R1. C3

Thanks all!
1 REPLY 1
Ksharp
Super User
Hi.
I recommend you to use proc compare based on your exact match.
If you want data step ,there is another alternative.


[pre]
data temp1;
input (a b c) ($);
id+1;
cards;
A1. R1. C1
A2. R1. C2
;
run;
data temp2;
input (_a _b _c) ($);
id+1;
cards;
A1. R1. C1
A2. R1. C2
;
run;
proc sort data=temp1;
by id;
run;
proc sort data=temp2;
by id;
run;
data x;
merge temp1 temp2;
by id;
run;
data result;
set x end=last nobs=_nobs;
retain error 0;
array left{*} $ a b c;
array right{*} $ _a _b _c;
do i=1 to dim(left);
if left{i} ne right{i} then do;
error=1;
leave;
end;
end;
if last and not error then do ;
do j=1 to _nobs;
set x point=j;
output;
end;
keep a b c;
end;
run;
[/pre]



Ksharp

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 1 reply
  • 934 views
  • 0 likes
  • 2 in conversation