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

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

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

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;

View solution in original post

1 REPLY 1
PeterClemmensen
Tourmaline | Level 20

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;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 349 views
  • 1 like
  • 2 in conversation