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: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

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