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

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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