BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hi all!


I have an issue when the Tranwrd function is passed dates. Though the input to the Tranwrd is 7/14/09 , the output is 71409. The same thing happens with brackets.If the input text has some brackets, the output does not have them.

Is there any way to solve this?

Thanks!
10 REPLIES 10
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Again, please share whatever SAS code you might be using, ideally in the form of a SAS log pasted in your post reply.

Also, consider that you appear to be using TRANWRD with something other than a "character" string -- I don't see why you would want to use TRANWRD with a SAS numeric DATE variable.

Can you convey what it is that you want to accomplish, with both INPUT and OUTPUT data examples, representing your object?

Scott Barry
SBBWorks, Inc.
deleted_user
Not applicable
This is my sas code:
25 data MYDATA.e_final;
26 set mydata.e_join;
27 array fld_nm_var (*) attr: ;
28 array fld_txt_var(*) fld:;
29 do i=1 to dim(fld_nm_var);
30 fld_txt = fld_txt_var(i);
31 put fld_txt;
32 fld_name = fld_nm_var(i);
33 put fld_name;
34 msg_txt =tranwrd(msg_txt,trim(fld_name),trim(fld_txt));
35 msg_txt = compress(msg_txt,'()');
36 drop fld_txt fld_name i;
37 PUT '****';
38 end;
39 run;

678954
Account#
****
$51,209
AggValue
****
4/2/09
EndDt
****
8
NumberOfTrans
****
Gary Johnson
PARTY NAME
****
4/2/09
StartDt
***
And this is my text message where the filed names (eg. startDt) have to be replaced with teh field txt (eg. 4/2/09).
"The activity is in the name of . There were cash transactions on account between and that aggregated to .

So though the StartDt has a value of 4/2/09 , when it actually gets replaced in the Message it becomes 4209.


Thanks!
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Honestly, you need to get a handle to understand the data in your input file, mydata.e_join, particularly using PROC CONTENTS to interrogate the variable types, where a FORMAT is being used, and also add PUTLOG _ALL_; commands to your DATA step along each path and with/outside DO/END loops. Also, use PROC FREQ to see unique value conditions so that you have confidence that your DATA step logic can handle the various data conditions.

Again, a SAS numeric type DATE variable internally has a value of "days since 1/1/1960" and if you are attempting to convert a character string and substitute with a date, you must use a PUT(,.) to translate to the desired "output format".

My recommendation (maybe even not for the first time) is that you should use a small data sample with various conditions to test all code-path processes -- use PUTLOG _ALL_; and get a clear understanding about every SAS log diagnostic message generated (and react to each with confidence, or come back here for guidance) -- but also do so with a SAS log pasted in your reply and not just your code.

Scott Barry
SBBWorks, Inc.
deleted_user
Not applicable
HEre is teh output of the PUTLOG which I used befor and after the TRANWRD function. I did not paste earlier because its too huge. What i can see is that the date gets inserted correctly in the msg txt but in the iteration after that, it becomes 4209. This date is also just a character variable in the Field_txt. Can you help please?
Cust_no=123 Cust_typ=EVENT Cust_id=1 MSG_ID=23456 MSG_SEQ_NO=1
MSG_TXT=The event is an activity in
the name of which indicates possible structuring of transactions to avoid currency transaction reporting limits.
There were cash transactions on account between and that aggregated to
alue/>. fld1=678954 fld2=$51,209 fld3=4/2/09 fld4=8 fld5=Gary Johnson fld6=4/2/09 fld7= attr1=Account# attr2=AggValue
attr3=EndDt attr4=NumberOfTrans attr5=PARTY NAME attr6=StartDt attr7= i=1 fld_txt=678954 fld_name=Account# _ERROR_=0 _N_=4
Cust_no=123 Cust_typ=EVENT Cust_id=1 MSG_ID=23456 MSG_SEQ_NO=1
MSG_TXT=The event is an activity in
the name of which indicates possible structuring of transactions to avoid currency transaction reporting limits.
There were cash transactions on account <678954/> between and that aggregated to
ue/>. fld1=678954 fld2=$51,209 fld3=4/2/09 fld4=8 fld5=Gary Johnson fld6=4/2/09 fld7= attr1=Account# attr2=AggValue
attr3=EndDt attr4=NumberOfTrans attr5=PARTY NAME attr6=StartDt attr7= i=1 fld_txt=678954 fld_name=Account# _ERROR_=0 _N_=4
**************************************************************************************************************
Cust_no=123 Cust_typ=EVENT Cust_id=1 MSG_ID=23456 MSG_SEQ_NO=1
MSG_TXT=The event is an activity in
the name of PARTY NAME which indicates possible structuring of transactions to avoid currency transaction reporting limits. Th
ere were NumberOfTrans cash transactions on account 678954 between StartDt and EndDt that aggregated to AggValue. fld1=678954
fld2=$51,209 fld3=4/2/09 fld4=8 fld5=Gary Johnson fld6=4/2/09 fld7= attr1=Account# attr2=AggValue attr3=EndDt
attr4=NumberOfTrans attr5=PARTY NAME attr6=StartDt attr7= i=2 fld_txt=$51,209 fld_name=AggValue _ERROR_=0 _N_=4
Cust_no=123 Cust_typ=EVENT Cust_id=1 MSG_ID=23456 MSG_SEQ_NO=1
MSG_TXT=The event is an activity in
the name of PARTY NAME which indicates possible structuring of transactions to avoid currency transaction reporting limits. Th
ere were NumberOfTrans cash transactions on account 678954 between StartDt and EndDt that aggregated to $51,209. fld1=678954
fld2=$51,209 fld3=4/2/09 fld4=8 fld5=Gary Johnson fld6=4/2/09 fld7= attr1=Account# attr2=AggValue attr3=EndDt
attr4=NumberOfTrans attr5=PARTY NAME attr6=StartDt attr7= i=2 fld_txt=$51,209 fld_name=AggValue _ERROR_=0 _N_=4
**************************************************************************************************************
Cust_no=123 Cust_typ=EVENT Cust_id=1 MSG_ID=23456 MSG_SEQ_NO=1
MSG_TXT=The event is an activity in
the name of PARTY NAME which indicates possible structuring of transactions to avoid currency transaction reporting limits. Th
ere were NumberOfTrans cash transactions on account 678954 between StartDt and EndDt that aggregated to $51,209. fld1=678954
fld2=$51,209 fld3=4/2/09 fld4=8 fld5=Gary Johnson fld6=4/2/09 fld7= attr1=Account# attr2=AggValue attr3=EndDt
attr4=NumberOfTrans attr5=PARTY NAME attr6=StartDt attr7= i=3 fld_txt=4/2/09 fld_name=EndDt _ERROR_=0 _N_=4
Cust_no=123 Cust_typ=EVENT Cust_id=1 MSG_ID=23456 MSG_SEQ_NO=1
MSG_TXT=The event is an activity in
the name of PARTY NAME which indicates possible structuring of transactions to avoid currency transaction reporting limits. Th
ere were NumberOfTrans cash transactions on account 678954 between StartDt and 4/2/09 that aggregated to $51,209. fld1=678954
fld2=$51,209 fld3=4/2/09 fld4=8 fld5=Gary Johnson fld6=4/2/09 fld7= attr1=Account# attr2=AggValue attr3=EndDt
attr4=NumberOfTrans attr5=PARTY NAME attr6=StartDt attr7= i=3 fld_txt=4/2/09 fld_name=EndDt _ERROR_=0 _N_=4
**************************************************************************************************************
Cust_no=123 Cust_typ=EVENT Cust_id=1 MSG_ID=23456 MSG_SEQ_NO=1
MSG_TXT=The event is an activity in
the name of PARTY NAME which indicates possible structuring of transactions to avoid currency transaction reporting limits. Th
ere were NumberOfTrans cash transactions on account 678954 between StartDt and 4209 that aggregated to $51,209. fld1=678954
fld2=$51,209 fld3=4/2/09 fld4=8 fld5=Gary Johnson fld6=4/2/09 fld7= attr1=Account# attr2=AggValue attr3=EndDt
attr4=NumberOfTrans attr5=PARTY NAME attr6=StartDt attr7= i=4 fld_txt=8 fld_name=NumberOfTrans _ERROR_=0 _N_=4
Cust_no=123 Cust_typ=EVENT Cust_id=1 MSG_ID=23456 MSG_SEQ_NO=1
MSG_TXT=The event is an activity in
the name of PARTY NAME which indicates possible structuring of transactions to avoid currency transaction reporting limits. Th
ere were 8 cash transactions on account 678954 between StartDt and 4209 that aggregated to $51,209. fld1=678954 fld2=$51,209
fld3=4/2/09 fld4=8 fld5=Gary Johnson fld6=4/2/09 fld7= attr1=Account# attr2=AggValue attr3=EndDt attr4=NumberOfTrans
attr5=PARTY NAME attr6=StartDt attr7= i=4 fld_txt=8 fld_name=NumberOfTrans _ERROR_=0 _N_=4
**************************************************************************************************************
Cust_no=123 Cust_typ=EVENT Cust_id=1 MSG_ID=23456 MSG_SEQ_NO=1
MSG_TXT=The event is an activity in
the name of PARTY NAME which indicates possible structuring of transactions to avoid currency transaction reporting limits. Th
ere were 8 cash transactions on account 678954 between StartDt and 4209 that aggregated to $51,209. fld1=678954 fld2=$51,209
fld3=4/2/09 fld4=8 fld5=Gary Johnson fld6=4/2/09 fld7= attr1=Account# attr2=AggValue attr3=EndDt attr4=NumberOfTrans
attr5=PARTY NAME attr6=StartDt attr7= i=5 fld_txt=Gary Johnson fld_name=PARTY NAME _ERROR_=0 _N_=4
Cust_no=123 Cust_typ=EVENT Cust_id=1 MSG_ID=23456 MSG_SEQ_NO=1
MSG_TXT=The event is an activity in
the name of Gary Johnson which indicates possible structuring of transactions to avoid currency transaction reporting limits.
There were 8 cash transactions on account 678954 between StartDt and 4209 that aggregated to $51,209. fld1=678954 fld2=$51,209
fld3=4/2/09 fld4=8 fld5=Gary Johnson fld6=4/2/09 fld7= attr1=Account# attr2=AggValue attr3=EndDt attr4=NumberOfTrans
attr5=PARTY NAME attr6=StartDt attr7= i=5 fld_txt=Gary Johnson fld_name=PARTY NAME _ERROR_=0 _N_=4
**************************************************************************************************************
Cust_no=123 Cust_typ=EVENT Cust_id=1 MSG_ID=23456 MSG_SEQ_NO=1
MSG_TXT=The event is an activity in
the name of Gary Johnson which indicates possible structuring of transactions to avoid currency transaction reporting limits.
There were 8 cash transactions on account 678954 between StartDt and 4209 that aggregated to $51,209. fld1=678954 fld2=$51,209
fld3=4/2/09 fld4=8 fld5=Gary Johnson fld6=4/2/09 fld7= attr1=Account# attr2=AggValue attr3=EndDt attr4=NumberOfTrans
attr5=PARTY NAME attr6=StartDt attr7= i=6 fld_txt=4/2/09 fld_name=StartDt _ERROR_=0 _N_=4
Cust_no=123 Cust_typ=EVENT Cust_id=1 MSG_ID=23456 MSG_SEQ_NO=1
MSG_TXT=The event is an activity in
the name of Gary Johnson which indicates possible structuring of transactions to avoid currency transaction reporting limits.
There were 8 cash transactions on account 678954 between 4/2/09 and 4209 that aggregated to $51,209. fld1=678954 fld2=$51,209
fld3=4/2/09 fld4=8 fld5=Gary Johnson fld6=4/2/09 fld7= attr1=Account# attr2=AggValue attr3=EndDt attr4=NumberOfTrans
attr5=PARTY NAME attr6=StartDt attr7= i=6 fld_txt=4/2/09 fld_name=StartDt _ERROR_=0 _N_=4
**************************************************************************************************************
Cust_no=123 Cust_typ=EVENT Cust_id=1 MSG_ID=23456 MSG_SEQ_NO=1
MSG_TXT=The event is an activity in
the name of Gary Johnson which indicates possible structuring of transactions to avoid currency transaction reporting limits.
There were 8 cash transactions on account 678954 between 4209 and 4209 that aggregated to $51,209. fld1=678954 fld2=$51,209
fld3=4/2/09 fld4=8 fld5=Gary Johnson fld6=4/2/09 fld7= attr1=Account# attr2=AggValue attr3=EndDt attr4=NumberOfTrans
attr5=PARTY NAME attr6=StartDt attr7= i=7 fld_txt= fld_name= _ERROR_=0 _N_=4
Cust_no=123 Cust_typ=EVENT Cust_id=1 MSG_ID=23456 MSG_SEQ_NO=1
MSG_TXT=The event is an activity in
the name of Gary Johnson which indicates possible structuring of transactions to avoid currency transaction reporting limits.
There were 8 cash transactions on account 678954 between 4209 and 4209 that aggregated to $51,209. fld1=678954 fld2=$51,209
fld3=4/2/09 fld4=8 fld5=Gary Johnson fld6=4/2/09 fld7= attr1=Account# attr2=AggValue attr3=EndDt attr4=NumberOfTrans
attr5=PARTY NAME attr6=StartDt attr7= i=7 fld_txt= fld_name= _ERROR_=0 _N_=4
**************************************************************************************************************



Thank you!
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Something is inconsistent, along with the observation that the logic process is inefficient because you are re-loading the array with every DATA step pass -- not using the MERGE / BY process as previously recommended.


Also, consider that you are using TRANWRD with values like "StartDt" and "4/2/09" yet I see in MSG_TXT there are strings with "<", ">", "/" and so I expect some assignment logic has to be in your code (maybe we're not seeing it all?) to remove the slash-character, which just happens to be part of the "character string date-value" you have that is also being manipulated.

You're going to need to dissect your program, by comment out logic, stopping/starting or doing a more useful PUTLOG 'Diag-nn' / _ALL_; command(s) peppered throughout your program's DATA step -- inside DO/END loops.

Mostly it's going to be up to you to diagnose what's going on. Your MSG_TXT variable is being manipulated somehow to strip-out the terminating-characters, as I mentioned, and we're not seeing all of that process.

Again, I encourage you to simplify the processing and work with a subset of fields to get the logic-flow working as you would expect, then expand the program slowly checking each next-larger set of data-values along the way.

Scott Barry
SBBWorks, Inc.
deleted_user
Not applicable
You are right. Not sure but I have this in my code:
msg_txt = compress(msg_txt,'()');

And this was causing the / to be removed from the dates too.

Thanks a lot!!!
Cynthia_sas
SAS Super FREQ
Hi:
I do NOT observe your same behavior of the COMPRESS function. If I run a test, as shown below, then I get ONLY the () being removed from my text string. (results at the end of this post) I would suggest that you report this odd behavior to Tech Support. Test Program:
[pre]
data testit;
length msg_txt msg_txt2 $100 datestr datestr2 $10;
msg_txt='07/21/2010 Twas (brillig and the )slithy /toves did gyre and \ gimble, in the wabe.';
msg_txt2 = compress(msg_txt,'()');
put '******************************';
put 'Original String --- ' msg_txt=;
put 'After Compress --- ' msg_txt2=;

datestr = '07/21/2010';
datestr2 = compress(datestr,'()');
put '******************************';
put 'Original String --- ' datestr=;
put 'After Compress --- ' datestr2=;
run;
[/pre]
cynthia
[pre]
1568 data testit;
1569 length msg_txt msg_txt2 $100 datestr datestr2 $10;
1570 msg_txt='07/21/2010 Twas (brillig and the )slithy /toves did gyre and \ gimble, in the wabe.';
1571 msg_txt2 = compress(msg_txt,'()');
1572 put '******************************';
1573 put 'Original String --- ' msg_txt=;
1574 put 'After Compress --- ' msg_txt2=;
1575
1576 datestr = '07/21/2010';
1577 datestr2 = compress(datestr,'()');
1578 put '******************************';
1579 put 'Original String --- ' datestr=;
1580 put 'After Compress --- ' datestr2=;
1581 run;

******************************
Original String --- msg_txt=07/21/2010 Twas (brillig and the )slithy /toves did gyre and \ gimble, in the wabe.
After Compress --- msg_txt2=07/21/2010 Twas brillig and the slithy /toves did gyre and \ gimble, in the wabe.
******************************
Original String --- datestr=07/21/2010
After Compress --- datestr2=07/21/2010

NOTE: The data set WORK.TESTIT has 1 observations and 4 variables.
NOTE: DATA statement used (Total process time):
real time 0.04 seconds
cpu time 0.00 seconds
[/pre]
deleted_user
Not applicable
yes you are right too. Because I am missing a slash in the code that I have pasted here. But I do have it.

Now here is my issue. If I remove these slashes using Compress it also removes the slashes in the dates, since thsi processing happens in a loop.
IS there a way to apeend '' to PARTY NAME , so that it now looks like
? Once I achieve this I can replace the entire word' instead of using a compress.
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Honestly....it would have taken you less time to test out the question yourself with a simple DATA step then it takes to ask and then get a reply.

Also, we've been down this path already with your SAS program, suggesting that your "template/variable data" MERGE use the TRANWRD, which appears to work fine, days ago.

As the DOC intends and as you've seen, COMPRESS is going to remove any specified character from the argument-1 variable. Your template MSG_TEXT variable and your ATTR variable need to contain the "target string" that you want to translate as a WORD using TRANWRD.

Scott Barry
SBBWorks, Inc.
deleted_user
Not applicable
I dont intend to use up your time but only get your opinions as you might be able to give me a better way of coding.
I am really not understanding the MERGE part that you mentioned, but what I did was use :
tfld_name = "<" || TRIM(LEFT(fld_name)) || "/>" ;
and then use TRANWRD.

Sorry if my posts caused you trouble.

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