BookmarkSubscribeRSS Feed
lei
Obsidian | Level 7 lei
Obsidian | Level 7

Hi i have an array called disch (*) disch1-disch9. 

I have a second array with empty values called dis_new(*) disch_new1-disch_new9. 

 

lei_0-1618775487894.png

disch_new takes on the value of disch if its value is after the disch prior. However, if the disch value is before, then i want disch_new to take on the prior. Therefore, dischnew1-6 are the same as disch1-6. However, dischnew7-dischnew9 all become 26June18:10:00:00.

 

I am not having any luck with the way I have it set up. If anyone can help that will be great.

 

Current code is this: 

 

ARRAY DIS(*) DISCH1 - DISCH&IDY;
ARRAY DIS_NEW (*) DISCH_NEW1 - DISCH_NEW&IDY.;

 

DIS_NEW[1]=DIS[1];
DIS_NEW[2]=DIS[2];

 

/* If discharge date ends prior to previous discharge*/

DO I=2 TO DIM(DIS_NEW);
IF DIS_NEW[I]<DIS[I-1] THEN DIS_NEW[I]=DIS[I-1];
ELSe DIS_NEW[I]=DIS[I];
END;

2 REPLIES 2
ChrisNZ
Tourmaline | Level 20

Like this?

do I = 1 to DIM(DIS_NEW);
  DIS_NEW[I] = max( DIS_NEW[I-1], DIS[I] );
end;

 

 

 

Patrick
Opal | Level 21

I believe for a DISCH_NEW<n> variable to never have a value lower than DISCH_NEW<n-1> the code @ChrisNZ posted needs a tweak. Below should do the job.

%let IDY=11;

data have;
  input DISCH1 - DISCH&IDY;
  datalines;
1 2 1 1 3 4 2 2 2 4 5
;

data want;
  set have;
  ARRAY DIS(*) DISCH1 - DISCH&IDY;
  ARRAY DIS_NEW (*) DISCH_NEW1 - DISCH_NEW&IDY.;
  DIS_NEW[1]=DIS[1];

  /* If discharge date ends prior to previous discharge*/
  DO I=2 TO DIM(DIS_NEW);
    IF DIS[I]<DIS_NEW[I-1] THEN
      DIS_NEW[I]=DIS_NEW[I-1];
    ELSe DIS_NEW[I]=DIS[I];
  END;
run;

proc print data=want;
run; 

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 707 views
  • 0 likes
  • 3 in conversation