BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
angeliquec
Quartz | Level 8

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:

  1. REF_TABLE

 

data REF_TABLE;

infile datalines dlm="|";

input STARTNUM ENDNUM GROUP :$10.;

datalines;

0|10|GROUP1

11|20|GROUP2

;

run;

 

 

  1. HAVE table

 

data HAVE;

infile datalines dlm="|";

input ADDRESS :$20.;

datalines;

1 STREET

#11 STREET

;

run;

 

 

  1. WANT table (expected result)

 

data WANT;

infile datalines dlm="|";

input ADDRESS :$20. GROUP :$10.;

datalines;

1 STREET|GROUP1

#11 STREET|GROUP2

;

run;

 

 

Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20
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;

View solution in original post

1 REPLY 1
novinosrin
Tourmaline | Level 20
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;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 908 views
  • 3 likes
  • 2 in conversation