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;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.