Help using Base SAS procedures

How can I find the earliest and latest date in my dataset?

Accepted Solution Solved
Reply
Contributor
Posts: 37
Accepted Solution

How can I find the earliest and latest date in my dataset?

I just want to visually see what the earliest and latest date is in my dataset for a specific date variable. How can I accomplish this?


Accepted Solutions
Solution
‎05-10-2017 09:15 AM
Super User
Posts: 6,938

Re: How can I find the earliest and latest date in my dataset?

 

proc sql;
select max(datevar) as maxdate, min(datevar) as mindate
from have;
quit;
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers

View solution in original post


All Replies
Respected Advisor
Posts: 3,777

Re: How can I find the earliest and latest date in my dataset?


confused_saser wrote:

I just want to visually see what the earliest and latest date is in my dataset for a specific date variable. How can I accomplish this?


min

max

Super User
Posts: 5,082

Re: How can I find the earliest and latest date in my dataset?

Calculate and print:

 

proc summary data=have;

var datevar;

output out=stats min=mindate max=maxdate;

run;

 

proc print data=stats;

var mindate maxdate;

format mindate maxdate yymmdd10.;

run;

 

Solution
‎05-10-2017 09:15 AM
Super User
Posts: 6,938

Re: How can I find the earliest and latest date in my dataset?

 

proc sql;
select max(datevar) as maxdate, min(datevar) as mindate
from have;
quit;
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Occasional Contributor
Posts: 10

Re: How can I find the earliest and latest date in my dataset?

You could alse try proc tabulate (assuming variable values are stored as sas date)

 

data test;
input dt date9.;
datalines;
01jul2009
01may2007
.
01dec2010
;
proc tabulate data=test format=date9.;
var dt;
table dt=''*(min='min date' max='max date') ;
run;

 

min date max date
01MAY200701DEC2010
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 421 views
  • 0 likes
  • 5 in conversation