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 ! .

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

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
  • 3 replies
  • 946 views
  • 0 likes
  • 3 in conversation