BookmarkSubscribeRSS Feed
thanikondharish
Calcite | Level 5

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.

Ready to join fellow brilliant minds for the SAS Hackathon?

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!
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
  • 2 replies
  • 1970 views
  • 0 likes
  • 3 in conversation