Without a very clear reason, as in terms of someone paying me real money, I would never create "date" values with different formats.
Please explain in some detail the actual advantage derived from turning " 01apr2022" into "2022/04/01" while at the same time requiring "2022/02/20" to become "20feb2022". Really what use is this???
Why do you have that N on your Input statement? There is only one variable. And your code as written will create a lot of missing values. As written you are attempting to read the variable Date as simple numeric variable and none of the values are valid as such.
IF you create SAS date values instead of random strings then you can apply a format as desired at time of use such as:
data date;
input date anydtdte15. ;
file print;
put "Date9 format" date= date9.;
put "yymmdd format" date= yymmdd10.;
put "ddmmyy format" date= ddmmyy10.;
put "mmddyy format" date= mmddyy10.;
cards;
01apr2022
01/05/2022
2022/02/28
2022/02/20
15-08-2020
;
The informat Anydtdte will attempt to read values as dates from different text layouts the potentially resemble dates.
Once you have a SAS date value then you can apply formats as desired for many purposes but generally to the VARIABLE, not per observation. SAS provides many date display formats plus with proc format you can even create your own.
You would have to provide a lot or description as to why a specific original layout gets displayed into a different one later and no such logic was provided.
@112211 wrote:
data date;
input date n $ 14. ;
cards;
01apr2022
01/05/2022
2022/02/28
2022/02/20
15-08-2020
;
I need output like following
n
2022/04/01
2022/05/01
28feb2022
20feb2022
2020/08/15