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,
what should be the output for
2016
un-18-2018
un-unk-2016
?
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
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;
I need to convert that to sas date varaible and display in yymmdd10.format
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.
for all the possible sas date informats i need to convert to yymmdd10. format,there I have given only few date informats,
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.
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
@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 😉
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.
here 18 is not month it is date, it id in mmddyy10. format
See the notes and solution in this paper
http://support.sas.com/resources/papers/proceedings11/117-2011.pdf
@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.
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 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.