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 ! .
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.