I'm new to using arrays. Can anyone help me fix this code? What I'm trying to do is shown in the data step below. Thanks!
data gfr0;
set gfr0;
array date[*] date1-date680;
do i=1 to dim(date);
if date[i]=closest then do;
egfr0= /* here is my problem /* ;
output;
leave;
end;
end;
run;
Here is my "slow" code:
data gfr0;
set gfr0;
if date1=closest then egfr0=reply1;
if date2=closest then egfr0=reply2;
if date3=closest then egfr0=reply3;
if date4=closest then egfr0=reply4;
if date5=closest then egfr0=reply5;
if date6=closest then egfr0=reply6;
if date7=closest then egfr0=reply7;
if date8=closest then egfr0=reply8;
if date9=closest then egfr0=reply9;
if date10=closest then egfr0=reply10;
if date11=closest then egfr0=reply11;
if date12=closest then egfr0=reply12;
if date13=closest then egfr0=reply13;
if date14=closest then egfr0=reply14;
if date15=closest then egfr0=reply15;
if date16=closest then egfr0=reply16;
if date17=closest then egfr0=reply17;
if date18=closest then egfr0=reply18;
if date19=closest then egfr0=reply19;
if date20=closest then egfr0=reply20;
if date21=closest then egfr0=reply21;
.....
I can't see your data, but something like this may do
data gfr0;
set gfr0;
array date[*] date1-date680;
array reply[*] reply1-reply680;
do i=1 to dim(date);
if date[i]=closest then do;
egfr0=reply[i];
output;
leave;
end;
end;
run;
I can't see your data, but something like this may do
data gfr0;
set gfr0;
array date[*] date1-date680;
array reply[*] reply1-reply680;
do i=1 to dim(date);
if date[i]=closest then do;
egfr0=reply[i];
output;
leave;
end;
end;
run;
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: