Hi all
I am trying to change a string throughout a whole dataset. I know i could do case when statements but there are to many variables. I am trying to use an array but i can quite get it to work, code below. Could anyone help please. Thanks
data data2;
set data;
array s _char_;
do _n_=1 to dim(s);
if s(_n_)="Timed" then (s(_n_)="Time");
end;
run;
Edit to add data there are about 50 of the St columns
| Num | rate | rate st | rate2 | rate2 st |
| 1 | 0.1 | Timed | 0.1 | Timed |
| 2 | 0.2 | New | 0.2 | New |
| 3 | 0.5 | Unchanged | 0.5 | Unchanged |
| 4 | 0.1 | New | 0.1 | Timed |
| 5 | 0.1 | Unchanged | 1 | Unchanged |
| 6 | 0.2 | Timed | 0.2 | Timed |
| 7 | 0.5 | Timed | 2 | New |
| 8 | 0.1 | Timed | 0.1 | Unchanged |
| 9 | 0.5 | Timed | 0.5 | Timed |
| 10 | 0.1 | New | 2.5 | New |
| 11 | 0.1 | Unchanged | 0.1 | Unchanged |
@Duvessa Hi and welcome to the SAS Community 🙂
Simply drop the parentheses..
data have;
input c1 $ n1 c2 $;
datalines;
Timed 1 abc
abc 1 Timed
;
data want;
set have;
array s _char_;
do _n_=1 to dim(s);
if s(_n_)="Timed" then s(_n_)="Time";
end;
run;
@Duvessa Hi and welcome to the SAS Community 🙂
Simply drop the parentheses..
data have;
input c1 $ n1 c2 $;
datalines;
Timed 1 abc
abc 1 Timed
;
data want;
set have;
array s _char_;
do _n_=1 to dim(s);
if s(_n_)="Timed" then s(_n_)="Time";
end;
run;
perfect thank you
Anytime 🙂
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!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.