data want;
set dep5 nobs=nobs;
want=nobs+1-_n_;
run;
please try
data have ;
input Top Date: mmddyy10. ;
format date date9.;
cards;
1 02/01/2018
2 02/05/2018
3 03/01/2018
;
proc sort data=have ;
by descending date;
run;
data want;
set have;
by descending date ;
retain count;
if first.date then count+1;
run;
First you sort your data by descending and count the records by id and then sort back to ascending.
data have;
format date date9.;
infile datalines dlm=" ";
input ID $ Date date9. ;
datalines;
A 01MAR2018
A 02MAR2018
A 03MAR2018
B 01MAR2018
B 02MAR2018
B 03MAR2018
;
run;
proc sort data=have;
by id descending date;
run;
data want;
set have;
by id;
if first.id then count=1;
else count+1;
run;
proc sort data=want;
by id date;
proc print data=want;
run;
data have ;
input Top Date: mmddyy10. ;
format date date9.;
cards;
1 02/01/2018
2 02/05/2018
3 03/01/2018
;
data want;
set have nobs=nobs;
want=nobs+1-_n_;
run;
Proper sort order will solve your problem. Please provide with some actual sample data with few records.
data want;
set dep5 nobs=nobs;
want=nobs+1-_n_;
run;
proc sort data=dep5;
by top descending date;
run;
data dep5;
set dep5;
by top;
if first.top then count=1;
else count+1;
run;
proc sort data=dep5;
by top date;
proc print data=dep5;
run;
could you please try this code, it is the same I provided earlier
not sure if you tried earlier but if you could try it will help you
proc sort data=have ;
by descending date;
run;
data want;
set have;
by descending date ;
retain count;
if first.date then count+1;
run;
proc sort data=want;
by id date;
run;
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.