BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
HannaZhang
Obsidian | Level 7

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 .

截图20190731112140.png

1 ACCEPTED SOLUTION

Accepted Solutions
hashman
Ammonite | Level 13

@HannaZhang:

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. 

View solution in original post

4 REPLIES 4
hashman
Ammonite | Level 13

@HannaZhang:

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
Ammonite | Level 13

@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. 

ChrisNZ
Tourmaline | Level 20

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

 

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 4 replies
  • 513 views
  • 1 like
  • 3 in conversation