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

 

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1284 views
  • 1 like
  • 3 in conversation