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
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.