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

Hi All,

Please can you help me with the below query

 

 

data a;
input  name   : $CHAR23. ;
datalines;
AddBaby 
AddMember 
AddPerson 
AddRemovePerson  
AddressUpdate  
AddressUpdateDiffState  
AddressUpdateNoSms  
run;

desired o/p -- I have a 1000 columns like this and not feasible to wite a case when statement . can I get this done through a different way..

 

 

 

Add Baby

Add Member

Add Person

Add Remove Person

Address Update

Address Update Diff State

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

And a more simplified variant.

 

data want;
set a;
length cleanName $50.;
cleanName = name;

do i=1 to 26;
  cleanName = transtrn(trim(cleanName), byte(64+i), ' '||byte(64+i));
end;

run;

proc print data=want;
run;

View solution in original post

3 REPLIES 3
Reeza
Super User

This uses a very basic approach:

You can fill in the rest of the letters - just remember to update the index to 26 for each letter.

 

data a;
input  name   : $CHAR23. ;
datalines;
AddBaby 
AddMember 
AddPerson 
AddRemovePerson  
AddressUpdate  
AddressUpdateDiffState  
AddressUpdateNoSms  
;;;;
run;

data want;
set a;
array _start(8) $ _temporary_ ('A', 'B','C', 'D', 'E', 'F', 'G', 'U');
array _end(8) $ _temporary_ (' A', ' B',' C', ' D', ' E', ' F', ' G', ' U');

cleanName = name;
do i=1 to dim(_start);
  cleanName = transtrn(trim(cleanName), trim(_start(i)), trim(_end(i)));
end;

run;

proc print data=want;
run;

@dennis_oz wrote:

Hi All,

Please can you help me with the below query

 

 

data a;
input  name   : $CHAR23. ;
datalines;
AddBaby 
AddMember 
AddPerson 
AddRemovePerson  
AddressUpdate  
AddressUpdateDiffState  
AddressUpdateNoSms  
run;

desired o/p -- I have a 1000 columns like this and not feasible to wite a case when statement . can I get this done through a different way..

 

 

 

Add Baby

Add Member

Add Person

Add Remove Person

Address Update

Address Update Diff State


 

Reeza
Super User

And a more simplified variant.

 

data want;
set a;
length cleanName $50.;
cleanName = name;

do i=1 to 26;
  cleanName = transtrn(trim(cleanName), byte(64+i), ' '||byte(64+i));
end;

run;

proc print data=want;
run;
Ksharp
Super User
data a;
input  name   : $CHAR23. ;
datalines;
AddBaby 
AddMember 
AddPerson 
AddRemovePerson  
AddressUpdate  
AddressUpdateDiffState  
AddressUpdateNoSms  
;;;;
run;

data want;
set a;
want=prxchange('s/([A-Z][a-z]*)/\1 /',-1,name);
run;

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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
  • 3 replies
  • 953 views
  • 3 likes
  • 3 in conversation