I have a REF_TABLE containing some ranges.
If street number from the HAVE table field (address field in text) falls under the ranges in the REF_TABLE, how can I classify the address field based on the range group in the REF_TABLE?
Here are the codes for the tables:
data REF_TABLE;
infile datalines dlm="|";
input STARTNUM ENDNUM GROUP :$10.;
datalines;
0|10|GROUP1
11|20|GROUP2
;
run;
data HAVE;
infile datalines dlm="|";
input ADDRESS :$20.;
datalines;
1 STREET
#11 STREET
;
run;
data WANT;
infile datalines dlm="|";
input ADDRESS :$20. GROUP :$10.;
datalines;
1 STREET|GROUP1
#11 STREET|GROUP2
;
run;
Thank you!
data REF_TABLE;
infile datalines dlm="|";
input STARTNUM ENDNUM GROUP :$10.;
datalines;
0|10|GROUP1
11|20|GROUP2
;
run;
data HAVE;
infile datalines dlm="|";
input ADDRESS :$20.;
datalines;
1 STREET
#11 STREET
;
run;
proc sql;
create table want as
select *
from have,ref_table
having startnum<= input(compress(address,,'kd'),8.)<=endnum;
quit;
data REF_TABLE;
infile datalines dlm="|";
input STARTNUM ENDNUM GROUP :$10.;
datalines;
0|10|GROUP1
11|20|GROUP2
;
run;
data HAVE;
infile datalines dlm="|";
input ADDRESS :$20.;
datalines;
1 STREET
#11 STREET
;
run;
proc sql;
create table want as
select *
from have,ref_table
having startnum<= input(compress(address,,'kd'),8.)<=endnum;
quit;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.