BookmarkSubscribeRSS Feed
molla
Fluorite | Level 6

Hi I have following data ,

 

dates

13APR1999

120499

2016-11-19

11-18-2016

2016

un-18-2018

un-unk-2016

 

I need to get all these dated to yymmdd10. format,

 

 

15 REPLIES 15
chrej5am
Quartz | Level 8

what should be the output for 

2016

un-18-2018

un-unk-2016

?

molla
Fluorite | Level 6

for 2106 the output should be 2016

for 

un-18-2018      2016-18-  

un-unk-2016     2016-  -   

there should be blank in the place of un and unk

Shmuel
Garnet | Level 18

If do not intend to convert the input into sas date variable then just read it a 

alphanumeric and replace the un/unk inro space:

 

data want;

infile datalines truncover;

input datex $10.;

  datex = tranword(datex, '  ','un');

  datex = translate(datex,' ','k');

datalines;

13APR1999

120499

2016-11-19

11-18-2016

2016

un-18-2018

un-unk-2016

; run;

molla
Fluorite | Level 6

I need to convert that to sas date varaible and display in yymmdd10.format

Shmuel
Garnet | Level 18

how would you interpre input like: 09-05-2015

is it a ddmmyy10. informat or mmddyy10. informat ?

 

and what about: 120499 - is ir 12apr1999 or 12apr2099 or 04dec1999 etc?

 

You cannot have a unque result unless you have some more restrictions.

molla
Fluorite | Level 6

for all the possible sas date informats i need to convert to yymmdd10. format,there I have given only few date informats,

 

chrej5am
Quartz | Level 8

You can not have this kind of output in the column with ordinary yymmdd10. format.

 

Either construct your own format

 

or

 

extract Year Month and Date from your input and based on availability of these values construct date column formatted as yymmdd10.

molla
Fluorite | Level 6

ok..

 

In the case of 13APR1999 input, can I compare the variable with sas datesets and convert them to yymmdd10. format, like

 

if datetest=date9. then 

d1=input(datetest,yymmdd10.)

 

In these way can i compare the varable with every sas date format and convert them to yyddmm10. format

Kurt_Bremser
Super User

@molla wrote:

for 2106 the output should be 2016

for 

un-18-2018      2016-18-  

un-unk-2016     2016-  -   

there should be blank in the place of un and unk


You can`t do that with the standard YYMMDD10. format; it needs a date value as input, and will always display days and months.

You will have to keep year, month and day in different variables so you can store the un/unk as missing values there, while preserving the non-missing year (or month).

BTW, there is no 18th month in the Gregorian calendar 😉

molla
Fluorite | Level 6

My requirement is consider a varaible which contain all the possible date informats of sas ,some of the months ,years are missing in the observations ,I need to convert all those to a common standard frmat yymdd10.

molla
Fluorite | Level 6

here 18 is not month it is date, it id in mmddyy10. format 

Reeza
Super User

See the notes and solution in this paper

 

http://support.sas.com/resources/papers/proceedings11/117-2011.pdf

Kurt_Bremser
Super User

@molla wrote:

My requirement is consider a varaible which contain all the possible date informats of sas ,some of the months ,years are missing in the observations ,I need to convert all those to a common standard frmat yymdd10.


This is only possible if you keep year, month and day in separate variables. A SAS date value (just like a date value in any programming environment) is a count of days from a certain offset (1960-01-01 in the case of SAS) and will always contain a valid month and day.

Reeza
Super User

Do you know the informat ahead of time? 

Or are you deriving it based on the appearance of the data?

 

As mentioned, mmddyy and ddmmyy are both valid informats that cannot be uniquely identified. 

 

If you don't know the format this may not be possible. 

The SAS catch all informat is ANYDTDTE. 

 

For your exact data, please post the expected results. 

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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
  • 15 replies
  • 2890 views
  • 1 like
  • 5 in conversation