hi,all.
I have a variable "InstanceName" ,I want to replace the text “n” of the "InstanceName" with the text “n=06”.
For example ,before: "第n周期第21±2天(队列一) (n=06)" ,
after: "第06周期第21±2天(队列一) ".
The variable "InstanceName" as follows;
THANKS a lot .
You can try the expression below, though there're many other (likely neater) ways to do it:
InstanceName = tranwrd (substr (InstanceName, 1, find (InstanceName, " (n="))
,"n"
,substr (InstanceName, 4 + find (InstanceName, " (n="), 2)
) ;
Kind regards
Paul D.
You can try the expression below, though there're many other (likely neater) ways to do it:
InstanceName = tranwrd (substr (InstanceName, 1, find (InstanceName, " (n="))
,"n"
,substr (InstanceName, 4 + find (InstanceName, " (n="), 2)
) ;
Kind regards
Paul D.
@hashman How come single-byte functions work here?
@ChrisNZ: Dunno. Perhaps the OP, though having given us a sample not in SBCS, has to deal with SBCS only or has somehow adapted the idea to D/MBCS.
I can only test in SBCS, but this should be close:
data t;
INSTANCENAME ='AAnBBCC (n=06) ';
NUMBER =kscan(INSTANCENAME,-1,' )=');
INSTANCENAME =kupdate(INSTANCENAME,kindexc(INSTANCENAME,'n'),1,ktrim(NUMBER));
INSTANCENAME =kscan(INSTANCENAME,1,' ');
put INSTANCENAME=;
run;
INSTANCENAME=AA06BBCC
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.