turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- Base SAS Programming
- /
- max date

Topic Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

04-26-2018 05:57 AM

Hi i have only character format dates this dates how to calculate maximum dates length also different one data set date length has $10 another data set length has $12 in this two data sets i want only max dates .

Ex;

data exp;

length dt $10;

input id dt $;

datalines;

101 2017/01/22

101 2018/01/20

102 2015/02/20

;

run;

data exp1;

length dt $12;

input id dt $;

datalines;

101 2017/01/25

101 2018/01/30

102 2015/02/19

;

run;

Thank you

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to teja5959

04-26-2018 06:02 AM

@teja5959 wrote:

Hi i have only character format dates this dates how to calculate maximum dates length also different one data set date length has $10 another data set length has $12 in this two data sets i want only max dates .

Ex;

data exp;

length dt $10;

input id dt $;

datalines;

101 2017/01/22

101 2018/01/20

102 2015/02/20

;

run;

data exp1;

length dt $12;

input id dt $;

datalines;

101 2017/01/25

101 2018/01/30

102 2015/02/19

;

run;

Thank you

Please try to rephrase your question in understandable English. Use periods to separate your sentences.

---------------------------------------------------------------------------------------------

Maxims of Maximally Efficient SAS Programmers

How to convert datasets to data steps

How to post code

Maxims of Maximally Efficient SAS Programmers

How to convert datasets to data steps

How to post code

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to teja5959

04-26-2018 06:08 AM

Convert to numeric dates. Get max. Its will be a lot of effort for no gain to keep them as text.

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to teja5959

04-26-2018 06:14 AM - edited 04-26-2018 06:16 AM

It's easy enough to run PROC CONTENTS on each data set. Then you can change the length to the longer length by hard-coding a length:

data exp;

length dt $ 12;

set exp;

run;

The LENGTH statement must come before the SET statement. However, you also have to realize that this may not be a good solution. What if the maximum length turned out to be $200? There's probably a lot of extra space being used unnecessarily. You should at least consider a solution that explores how many characters are needed. For example:

data test_exp;

set exp;

len_dt = lengthn(dt);

run;

proc means data=test_exp max maxdec=0;

var len_dt;

run;

That program tells you how many characters are actually needed. You would need to run a similar program for each of your data sets, to discover how many characters are needed across all data sets.

And I agree with @RW9 ... it is worth learning how SAS handles dates, and converting your dates to numeric values. The solution I provided is more general, and can be applied to non-date variables.