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 |
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;
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
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;
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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.
Ready to level-up your skills? Choose your own adventure.