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

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 634 views
  • 0 likes
  • 2 in conversation