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;

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
  • 575 views
  • 3 likes
  • 2 in conversation