BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
jati
Calcite | Level 5

I'm new in sas, I need help how to move specific word to new column in sas, with the data below :

 

address :

TEGALASEM RT 005 RW 003 KEL SUMBERGONDO KEC BUMIAJI

CEMARA BARU III F 512 RT 009 RW 017 KEL JATIMULYA KEC TAMBUN SELATAN

JL LIGAR TIMUR 1 NO 1 RT 01/13 KEL CIBEUNYING

 

result :

KEL :                                KEC :        

SUMBERGONDO             BUMIAJI

JATIMULYA                       TAMBUN SELATAN

CIBEUNYING

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
data have;
input have $80.;
cards;
TEGALASEM RT 005 RW 003 KEL SUMBERGONDO KEC BUMIAJI
CEMARA BARU III F 512 RT 009 RW 017 KEL JATIMULYA KEC TAMBUN SELATAN
JL LIGAR TIMUR 1 NO 1 RT 01/13 KEL CIBEUNYING
;
data want;
 set have;
 pid=prxparse('/(KEL\s+\w+\s+)(KEC[\w\s]+)?/i');
 if prxmatch(pid,have) then do;
   kel=left(substr(prxposn(pid,1,have),4));
   kec=left(substr(prxposn(pid,2,have),4));
 end;
drop pid;
run;

View solution in original post

5 REPLIES 5
PeterClemmensen
Tourmaline | Level 20

What is the logic here?

jati
Calcite | Level 5

 

if "KEL" in the address then move to the KEL column

if the "KEC" in the address then move to the KEL column

 

Data :

noaddress
1TEGALASEM RT 005 RW 003 KEL SUMBERGONDO KEC BUMIAJI
2CEMARA BARU III F 512 RT 009 RW 017 KEL JATIMULYA KEC TAMBUN SELATAN
3JL LIGAR TIMUR 1 NO 1 RT 01/13 KEL CIBEUNYING

 

Result 

NOKELKEC
1SUMBERGONDO             BUMIAJI
2JATIMULYA                        TAMBUN SELATAN
3CIBEUNYING 
Ksharp
Super User
data have;
input have $80.;
cards;
TEGALASEM RT 005 RW 003 KEL SUMBERGONDO KEC BUMIAJI
CEMARA BARU III F 512 RT 009 RW 017 KEL JATIMULYA KEC TAMBUN SELATAN
JL LIGAR TIMUR 1 NO 1 RT 01/13 KEL CIBEUNYING
;
data want;
 set have;
 pid=prxparse('/(KEL\s+\w+\s+)(KEC[\w\s]+)?/i');
 if prxmatch(pid,have) then do;
   kel=left(substr(prxposn(pid,1,have),4));
   kec=left(substr(prxposn(pid,2,have),4));
 end;
drop pid;
run;
jati
Calcite | Level 5
thank you its working

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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
  • 5 replies
  • 1579 views
  • 1 like
  • 4 in conversation