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
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;
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);
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;
Thanks Sharp ! .
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.
Ready to level-up your skills? Choose your own adventure.