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

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 

 

Numraterate st rate2rate2 st 
10.1Timed0.1Timed
20.2New0.2New
30.5Unchanged 0.5Unchanged 
40.1New0.1Timed
50.1Unchanged 1Unchanged 
60.2Timed0.2Timed
70.5Timed2New
80.1Timed0.1Unchanged 
90.5Timed0.5Timed
100.1New2.5New
110.1Unchanged 0.1Unchanged 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

@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;

View solution in original post

4 REPLIES 4
ed_sas_member
Meteorite | Level 14

Hi @Duvessa 

 

Could you please share some sample data?

Thanks a lot,

 

Best,

PeterClemmensen
Tourmaline | Level 20

@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
Calcite | Level 5

perfect thank you