DATA Step, Macro, Functions and more

Change the Field value

Accepted Solution Solved
Reply
Contributor
Posts: 33
Accepted Solution

Change the Field value

Hi,

 

I have the field name called CIN and CLIENT_ID.

If the program type as “E” then the ID formatted XX12345X, should be sent in the CIN field instead of CLIENT_ID

If the program type as “E” then the  ID formatted 70017001, should be sent in the CLIENT_ID field instead of CIN.

 

CIN : 8 alpha numeric (ex.XX02345X)

CLIENT_ID: 8 numeric (ex.70005234)

 

  

  

Program type

CLIENT_ID

CIN

Membno

E

NF01984Y

 

42500000

E

AB09099Y

 

43567899

E

 

70017984

56798000

 

Need to show as below values:

 

Program type

CLIENT_ID

CIN

Membno

E

 

NF01984Y

42500000

E

 

AB09099Y

43567899

E

70017984

 

56798000

 

Thanks in Advance


Accepted Solutions
Solution
‎10-04-2016 11:54 PM
Super User
Posts: 10,044

Re: Change the Field value



data have;
input (Program 
CLIENT_ID
CIN
Membno) (: $20.);
cards;
E
NF01984Y
. 
42500000
E
AB09099Y
. 
43567899
E
. 
70017984
56798000
;
run;

data want;
 set have;
 if not missing(client_id) then do;
  if prxmatch('/^[a-z][a-z]\d{5}[a-z]$/i',strip(client_id)) then new_cin=client_id;
  if prxmatch('/^\d{8}$/',strip(client_id)) then new_id=client_id;
 end;
 
 if not missing(cin) then do;
  if prxmatch('/^[a-z][a-z]\d{5}[a-z]$/i',strip(cin)) then new_cin=cin;
  if prxmatch('/^\d{8}$/',strip(cin)) then new_id=cin;
 end;
run;


View solution in original post


All Replies
Trusted Advisor
Posts: 1,583

Re: Change the Field value

[ Edited ]

Is there a variable containing the program type 'E' ? If yes - what is its name ?

 

My first thought was that you just need rename of the two variables:

 

data want;

 set have(rename=(CIN=Client_id Client_id=CIN));

run;

 

If rename do the work, then even better is to use PROC DATASETS to renmae the varible names.

It is much faster and saves disk space (eliminates copy of the dataset);

Solution
‎10-04-2016 11:54 PM
Super User
Posts: 10,044

Re: Change the Field value



data have;
input (Program 
CLIENT_ID
CIN
Membno) (: $20.);
cards;
E
NF01984Y
. 
42500000
E
AB09099Y
. 
43567899
E
. 
70017984
56798000
;
run;

data want;
 set have;
 if not missing(client_id) then do;
  if prxmatch('/^[a-z][a-z]\d{5}[a-z]$/i',strip(client_id)) then new_cin=client_id;
  if prxmatch('/^\d{8}$/',strip(client_id)) then new_id=client_id;
 end;
 
 if not missing(cin) then do;
  if prxmatch('/^[a-z][a-z]\d{5}[a-z]$/i',strip(cin)) then new_cin=cin;
  if prxmatch('/^\d{8}$/',strip(cin)) then new_id=cin;
 end;
run;


Contributor
Posts: 33

Re: Change the Field value

Thanks Sharp ! .

 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 267 views
  • 0 likes
  • 3 in conversation