BookmarkSubscribeRSS Feed
teja5959
Obsidian | Level 7

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

3 REPLIES 3
Kurt_Bremser
Super User

@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.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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

Astounding
PROC Star

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.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1890 views
  • 0 likes
  • 4 in conversation