I have a SAS dataset called exampleDs
which contains the following date variable (called OPEN_DT
):
I need to create a new variable called open_date
from OPEN_DT
but has a different informat (not just the display format), which is MMYY5.
. So, the resulting dataset would look like this:
I have tried this code:
data newExampleDs;
set exampleDs;
open_date = month(OPEN_DT);
run;
But it returns the number of the month.
Can anyone help me please?
The INFORMAT attached to a variable has no real impact on an existing dataset. It is only used when using an INPUT statement to create values from text.
If you just copy the values and attach a different format to the variable then it will display as you want. What you show is style generated by the MONYY5. format.
You might want to change the VALUE stored in the variable so all values for a month, like January 2024 say, are the same. Normally you store dates used to represent an interval as the beginning of the interval.
data newExampleDs;
set exampleDs;
open_date = intnx('month',OPEN_DT,0);
format open_date monyy5.;
run;
Note: Displaying years without the century can lead to confusion. You should use MONYY7. format instead.