Hi All,
Can you please help me with the following formatting change ?
I have a date column (format yynnm4. for example 1803 representing 2018 March)
I want to create the exact same column but as text ( for example text 1803, or as an integer 1803).
Thanks,
length crdate $4;
crdate = put(numdate,yymmn4.);
you just use the display format in a put() function.
Depending on what you mean by "exact same column".
A new variable with the character value can be done with:
data want; set have; datechar = put(date,yymmn4.); run;
I believe your description confused the M and N in the format.
If you mean to change the existing variable you can't directly. Once a variable is created the type is fixed. You would have to rename your existing variable and create a variable with the same name using similar code:
data want; set have (rename=(date=olddate); date = put(olddate,yynnm4.); drop olddate; run;
length crdate $4;
crdate = put(numdate,yymmn4.);
you just use the display format in a put() function.
Why? It's much better to store dates as SAS Date values and not as strings.
You can use a put function with a format to write a numerical value as a string. You then assign the result of this to a new variable of type character.
date_string_var=put(sasdate_var, yymmn4.);
Thanks all, this worked !!!
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.