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
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 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 833 views
  • 1 like
  • 4 in conversation