BookmarkSubscribeRSS Feed
thanikondharish
Fluorite | Level 6

data s ;
name='sas programmer ' ;
run;

how to insert 'H' in name variable see like below?

Note: without using tranwrd function,substr function

 

name

sas proHgrammer

2 REPLIES 2
gamotte
Rhodochrosite | Level 12

Hello,

 

What is the ultimate goal and why the relevant tools should be forbidden ?

What criterion does tell us where the letter should be inserted ?

 

This does what you want but I doubt it really answers your needs.

 

data s ;
name='sas programmer ' ;
name2=cats(scan(name,1,'g'),'Hg',scan(name,2,'g'));
run;

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Why can you not use the functions designed to manipulate strings?  To put it another, your not allowed to use the keyboard, now type your messages in - doesn't make any sense right?  

Anyways, you would have to loop over the array of characters manually, see below code:

data s;
  /* Note you have to assign a length which is greater than the string length + 1 other wise there will be truncation */
  length name new_name $200; 
  name='sas programmer ';
  do i=1 to lengthn(name);
    if char(name,i-1)=" " then new_name=cat(strip(new_name)," ",char(name,i)); 
    else new_name=cats(new_name,char(name,i));
    if i=7 then new_name=cats(new_name,"H");
  end;
run;

You can sees how much of a waste of time that is!


And please remember to mark all questions with answered when you have your answer.

And please use the code window - its the {i} above post area - to post code.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

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!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 2 replies
  • 2439 views
  • 0 likes
  • 3 in conversation