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: 10,217

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

Posted in reply to confused_saser

 

proc sql;
select max(datevar) as maxdate, min(datevar) as mindate
from have;
quit;
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code

View solution in original post


All Replies
Respected Advisor
Posts: 3,852

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

Posted in reply to confused_saser

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: 6,762

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

Posted in reply to confused_saser

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: 10,217

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

Posted in reply to confused_saser

 

proc sql;
select max(datevar) as maxdate, min(datevar) as mindate
from have;
quit;
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Occasional Contributor
Posts: 10

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

Posted in reply to confused_saser

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
  • 1779 views
  • 0 likes
  • 5 in conversation