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 !!!
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.