BookmarkSubscribeRSS Feed
Vasundha
Calcite | Level 5

Right

PeterClemmensen
Tourmaline | Level 20

If so, then try this

 

Data have;
Input in_date : date9. readings;
format in_date date9.;
Datalines;
04Nov2022 40
08Nov2022 89
09NOV2022 61
10NOV2022 60
11NOV2022 67
15NOV2022 45
16NOV2022 15
17NOV2022 12
18NOV2022 10
;
run;

data want;
  do p = max(1, n - 6) to n;
    set have nobs = n point = p;
    output;
  end;
  stop;
run;
Vasundha
Calcite | Level 5

I really appreciate your efforts however I was wondering that can't it be possible in input table in a data step?.

 

Vasundha
Calcite | Level 5

Alright, Thanks!.

PeterClemmensen
Tourmaline | Level 20

If by 'input', you mean directly in the set(someoption = )statment, then no.

Vasundha
Calcite | Level 5

Got it, Thank you for your precious time!.

Kurt_Bremser
Super User

Brute force approach:

proc sort
  data=have (keep=date)
  out=dates
  nodupkey
;
by descending date;
run;

data _null_;
set dates point=7;
call symputx("cutoff",date);
stop;
run;

data want;
set have;
where date ge &cutoff.;
run;

But the PROC RANK method is more efficient.

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!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 22 replies
  • 1127 views
  • 0 likes
  • 4 in conversation