- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I have this string: "Cdtr":{"Nm":"DEUTSCHE BANK"}
How can I implement this in SAS like the function
regexp_extract(fulltxinf_intx, '"Cdtr":."Nm":"([^"]+)', 1) as String_Ort
Thanks
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
that's why I get this result: {"ar:pacs.003.002.04":{DEUTSCHE BANK
data HAVE;
input STR1 &:$300.;
cards;
{"ar:pacs.003.002.04":{"Cdtr":{"Nm":"DEUTSCHE BANK"},"CdtrAcct":{"Id":{"IBAN":"DE0111111111111111111100"}}
{"Cdtr":{"Nm":"DEUTSCHE BANKX"},"CdtrAcct":{"Id":{"IBAN":"DE0111111111111111111100"}}
{"ar:pacs.003.002.04":{"Cxxx":{"Nm":"DEUTSCHE BANKY"},"CdtrAcct":{"Id":{"IBAN":"DE0111111111111111111100"}}
run;
proc sql;
select ifc( prxchange('s/.*"Cdtr":{"Nm":"([^"]+).*/\1/', 1, STR1) = STR1, ' ', prxchange('s/.*"Cdtr":{"Nm":"([^"]+).*/\1/', 1, STR1) ) as STRING_ORT
from HAVE;
quit;
I cater for cases when there is not matching pattern with the ifc()
test.
STRING_ORT |
---|
DEUTSCHE BANK |
DEUTSCHE BANKX |
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
The function returns me the result DEUTSCHE BANK, that the parameters Cdtr":{"Nm": are in front of it.
My string: "Cdtr":{"Nm":"DEUTSCHE BANK"}
regexp_extract(string, '"Cdtr":."Nm":"([^"]+)', 1) as String_Ort
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Can you give a few more examples of strings you would like to parse?
Next webinar will be in January 2025. Until then, check out our archives: https://www.basug.org/videos. And be sure to subscribe to our our email list.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Like this?
data T;
STR1 = '"Cdtr":{"Nm":"DEUTSCHE BANK"}';
STR2 = prxchange('s/"Cdtr":."Nm":"([^"]+).*/\1/', 1, STR1);
put STR2=;
run;
STR2=DEUTSCHE BANK
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Not too sure why you have
STR2 = prxchange('s/"Cdtr":."Nm":"([^"]+).*/\1/', 1, STR1);
I'd replace the . with a {
STR2 = prxchange('s/"Cdtr":{"Nm":"([^"]+).*/\1/', 1, STR1);
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
The problem is, the first record is with {"Cdtr":{"Nm":"DEUTSCHE BANK"} .
The second record is with '{"Cdtr":{"Nm":"VERGOELST GMBH"}'
according to the constant variables {"Cdtr":{"Nm":, each record in the file has a different value.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Swap with the names of your variables.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
my string is 300 - 400 Bytes long.
{"Cdtr":{"Nm":"DEUTSCHE BANK"},"CdtrAcct":{"Id":{"IBAN":"DE0111111111111111111100"}},
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
my string begins
{"ar:pacs.003.002.04":{"Cdtr":{"Nm":"DEUTSCHE BANK"},"CdtrAcct":{"Id":{"IBAN":"DE0111111111111111111100"}}
that's why I get this result: {"ar:pacs.003.002.04":{DEUTSCHE BANK
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Can you please give a few examples (just 5-10) of the full string you are trying to parse? It will help people help you.
Next webinar will be in January 2025. Until then, check out our archives: https://www.basug.org/videos. And be sure to subscribe to our our email list.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
that's why I get this result: {"ar:pacs.003.002.04":{DEUTSCHE BANK
data HAVE;
input STR1 &:$300.;
cards;
{"ar:pacs.003.002.04":{"Cdtr":{"Nm":"DEUTSCHE BANK"},"CdtrAcct":{"Id":{"IBAN":"DE0111111111111111111100"}}
{"Cdtr":{"Nm":"DEUTSCHE BANKX"},"CdtrAcct":{"Id":{"IBAN":"DE0111111111111111111100"}}
{"ar:pacs.003.002.04":{"Cxxx":{"Nm":"DEUTSCHE BANKY"},"CdtrAcct":{"Id":{"IBAN":"DE0111111111111111111100"}}
run;
proc sql;
select ifc( prxchange('s/.*"Cdtr":{"Nm":"([^"]+).*/\1/', 1, STR1) = STR1, ' ', prxchange('s/.*"Cdtr":{"Nm":"([^"]+).*/\1/', 1, STR1) ) as STRING_ORT
from HAVE;
quit;
I cater for cases when there is not matching pattern with the ifc()
test.
STRING_ORT |
---|
DEUTSCHE BANK |
DEUTSCHE BANKX |
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
This is the best solution. Thank you very much.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
This solution for SAS can 100% replace the regexp_extract function.