BookmarkSubscribeRSS Feed
teja5959
Fluorite | Level 6

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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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