DATA Step, Macro, Functions and more

Help on how to match

Reply
N/A
Posts: 1

Help on how to match

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!
Super User
Posts: 9,681

Re: Help on how to match

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
Ask a Question
Discussion stats
  • 1 reply
  • 110 views
  • 0 likes
  • 2 in conversation