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

 Hi,  I'm trying to find if there is a space after the last 3 digits then it's a canadian address otherwise it's US.

 

field

23 Yonge st.  M4H 6F7

23 Yonge st. 902910

827 Bla Bla Rd. T7G 7K2

Sammy Rd. 38278

 

where there is a postal code I'd say Canadian and 2 and 4 are US.. So I figured if there is a space after the last 3 digits from the right then it's  Can, otherwise US.

Thnks

1 ACCEPTED SOLUTION

Accepted Solutions
Jagadishkatam
Amethyst | Level 16

Please try perl as below

 

data want;
set have;
if prxmatch('m/\s\d\w\d$/',strip(field)) then flag='Can';
else flag='US';
run;
Thanks,
Jag

View solution in original post

4 REPLIES 4
Jagadishkatam
Amethyst | Level 16

Please try perl as below

 

data want;
set have;
if prxmatch('m/\s\d\w\d$/',strip(field)) then flag='Can';
else flag='US';
run;
Thanks,
Jag
ChrisNZ
Tourmaline | Level 20

You could use variations of:

 

if length(scan(ADDRESS,-1)) in (3,6) then COUNTRY='CANADA';

Reeza
Super User

A different option

 

1. Use COUNTW to determine the number of words

2. Find last word

3. If Length = 5 then it's US, otherwise, it's CAN.

 

The Perl is more efficient though

 

length country $8.;

n_words = countw(text);
last_word = scan(text, n_words);

if length(last_word)=3 then country = 'CAN';
else if length(last_word)=5 then country='US';
else country='CHECKME';
kiranv_
Rhodochrosite | Level 12

something like this

data want;
set have;
if prxmatch("m/\s.{3}$/oi",trim(addr_ln_1))> 0 then cntry='CAN';
else cntry='US';
run;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 4 replies
  • 2814 views
  • 3 likes
  • 5 in conversation