In SAS EG, in a data step, I am trying to convert from a date to a string in the following formats:
JUN18
to '201806'
I am able to convert the opposite direction using a data step as follows:
data date;
length b $6;
b='201806';
new_b=input(b, yymmn6.);
format new_b monyy5.;
The result is that new_b
= JUN18
. I have tried the opposite direction and something is just off and I can't figure out what I am missing. Does anyone know how to convert these data types?
Thanks.
Use the
PUT
orPUTN
function to convert a SAS date value to a string containing a date representation.The
VVALUE
function can be used to obtain the formatted value (the data value representation in a character string) of a variable using its current format attribute.You need to switch your formats and informats. In the INPUT function, you put the format your data looks like, in this case, monyy5 and then the format is what you want your data to look like, in this case, YYMMN6.
Switching them is all you need.