0

I want to create a data set where I only want to keep 5 specific dates. So my &date is 31mar2020 and &enddate is 31mar2025 and I only want to keep 31mar every year until 2025.

With my code below it creates dates for everyday up to 31mar2025 and thats to much so I only want to keep 5 specific dates.

How can i do that?

Thank you

  DATA LOOP;FORMAT ROLL_BASE_DT DATE9.;DO  ROLL_BASE_DT =&DATE TO &ENDdate;OUTPUT;END;RUN;

enter code here

enter code here

2 Answers2

2

You can use commas in the DO statement to list multiple values.

do date='31mar2021'd,'31mar2022'd,'31mar2023'd,'31mar2024'd,'31mar2025'd;
  ...
end;

You could loop over the YEAR value instead.

do year=2021 to 2025;
   date=mdy(3,31,year);
  ...
end;

You could use INTNX() to increment the date by YEAR. You can use INTCK() to figure out how many times to run the loop.

do index=0 to intck('year',&DATE,&ENDdate);
  date=intnx('year',&date,index,'s');
  ...
end;
Tom
  • 47,574
  • 2
  • 16
  • 29
0

If it's just the 5 dates you want, you could use the cards input (I know of it but have never used it personally).

Alternatively, rather than using a loop just set the values individually with the output keyword after each time you set the value. That should do it.

Laebrye
  • 96
  • 5