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;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.