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
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: