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

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

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User


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

3 REPLIES 3
Shmuel
Garnet | Level 18

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);

Ksharp
Super User


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;


cho16
Obsidian | Level 7

Thanks Sharp ! .

 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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