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
@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.
Convert to numeric dates. Get max. Its will be a lot of effort for no gain to keep them as text.
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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.