Hi SAS experts,
I need your advice regarding above situation.
I would like to have variables: expect1, expect2, expect3, expect4 by using y_2016, y_2017, y_2018, y_2019 variables.
For expect1 variables, I use coalesce to get this index date. Something like below.
expect1= coalesce(y_2016, y_2017, y_2018, y_2019) ;
but I would like to keep the missing values if there is no information.
(I would like to keep missing values in the row)
In this case, each row represent one patient dates.
Goal is to have t, t+1, t+2, t+3, t+4 information.
Many thanks!
data have ; input id y_2016 y_2017 y_2018 y_2019 expect1 expect2 expect3 expect4; CARDS; a 201604 . . 201901 201604 . . 201901 b . 201708 201811 . 201708 201811 . . c . . . 201911 201911 . . . ; run;
Figure out where to start. Then copy.
data have ;
input id $ have1-have4;
cards;
a 201604 . . 201901
b . 201708 201811 .
c . . . 201911
d . . . .
;
data want;
set have ;
array old have1-have4;
array new want1-want4;
do start=1 to dim(old) until (not missing(old[start])); end;
target=1;
do index=start to dim(old);
new[target]=old[index];
target+1;
end;
drop index target;
run;
Figure out where to start. Then copy.
data have ;
input id $ have1-have4;
cards;
a 201604 . . 201901
b . 201708 201811 .
c . . . 201911
d . . . .
;
data want;
set have ;
array old have1-have4;
array new want1-want4;
do start=1 to dim(old) until (not missing(old[start])); end;
target=1;
do index=start to dim(old);
new[target]=old[index];
target+1;
end;
drop index target;
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.