Hi
I would like to match the value in the following information to the input table. Please, see the desired output
Value | Value |
KET | Cars |
KOT | Jeans |
PERSE | Dress |
Van | Computer |
INPUTS |
KOT |
KOT |
VAN |
KOT |
KOT |
KOT |
VAN |
KOT |
KOT |
PERSE |
VAN |
VAN |
PERSE |
KOT |
KOT |
KOT |
KOT |
VAN |
PERSE |
VAN |
KOT |
VAN |
KET |
VAN |
VAN |
KET |
KET |
VAN |
KOT |
KOT |
VAN |
VAN |
KOT |
VAN |
VAN |
KET |
PERSE |
PERSE |
INPUTS | OUTPUT |
KOT | Jeans |
KOT | Jeans |
VAN | Computer |
KOT | Jeans |
KOT | Jeans |
KOT | Jeans |
VAN | Computer |
KOT | Jeans |
KOT | Jeans |
PERSE | Dress |
VAN | Computer |
VAN | Computer |
PERSE | Dress |
KOT | Jeans |
KOT | Jeans |
KOT | Jeans |
KOT | Jeans |
VAN | Computer |
PERSE | Dress |
VAN | Computer |
KOT | Jeans |
VAN | Computer |
KET | Cars |
VAN | Computer |
VAN | Computer |
KET | Cars |
KET | Cars |
VAN | Computer |
KOT | Jeans |
KOT | Jeans |
VAN | Computer |
VAN | Computer |
KOT | Jeans |
VAN | Computer |
VAN | Computer |
KET | Cars |
PERSE | Dress |
PERSE | Dress |
if you want just a SQL match this will give you what you want as long as Van and VAN are the same in your expectations.
data have;
input ID $ Value $;
datalines;
KET Cars
KOT Jeans
PERSE Dress
Van Computer
;
data inputs;
input ID $;
cards;
KOT
KOT
VAN
KOT
KOT
KOT
VAN
KOT
KOT
PERSE
VAN
VAN
PERSE
KOT
KOT
KOT
KOT
VAN
PERSE
VAN
KOT
VAN
KET
VAN
VAN
KET
KET
VAN
KOT
KOT
VAN
VAN
KOT
VAN
VAN
KET
PERSE
PERSE
;
proc sql;
create table want as
select a.*, b.value
from inputs as a,
have as b
where upcase(a.id) = upcase(b.id);
quit;
Looks like a case of a custom format. Use the information in the look up table to create a format.
Apply the format to the input variable as needed.
if you want just a SQL match this will give you what you want as long as Van and VAN are the same in your expectations.
data have;
input ID $ Value $;
datalines;
KET Cars
KOT Jeans
PERSE Dress
Van Computer
;
data inputs;
input ID $;
cards;
KOT
KOT
VAN
KOT
KOT
KOT
VAN
KOT
KOT
PERSE
VAN
VAN
PERSE
KOT
KOT
KOT
KOT
VAN
PERSE
VAN
KOT
VAN
KET
VAN
VAN
KET
KET
VAN
KOT
KOT
VAN
VAN
KOT
VAN
VAN
KET
PERSE
PERSE
;
proc sql;
create table want as
select a.*, b.value
from inputs as a,
have as b
where upcase(a.id) = upcase(b.id);
quit;
I guess you want keep the order of obs in table INPUTS.
data have;
input ID $ Value $;
datalines;
KET Cars
KOT Jeans
PERSE Dress
VAN Computer
;
data inputs;
input ID $;
cards;
KOT
KOT
VAN
KOT
KOT
KOT
VAN
KOT
KOT
PERSE
VAN
VAN
PERSE
KOT
KOT
KOT
KOT
VAN
PERSE
VAN
KOT
VAN
KET
VAN
VAN
KET
KET
VAN
KOT
KOT
VAN
VAN
KOT
VAN
VAN
KET
PERSE
PERSE
;
data want;
if _n_=1 then do;
if 0 then set have;
declare hash h(dataset:'have');
h.definekey('id');
h.definedata('value');
h.definedone();
end;
set inputs;
call missing(value);
rc=h.find();
drop rc;
run;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.