Hi,
I'm new to SAS and trying to learn my way around it. I have a data set with a column populated with dates in Character format.
Ex: 092009 for September 2009, the properties of the column say its a Character variable with $30.
How can I change the whole column of dates into monyy7. format or to any other date format for that matter?
/*********************/
/** SAMPLE DATASET **/
/*********************/
DATA WORK.Have;
FORMAT Date_Orig $30.;
INFORMAT Date_Orig $30.;
INPUT Date_Orig;
CARDS;
092009
102009
112009
122009
;
DATA WORK.Want (RENAME=(date_new=Date_Orig));
SET WORK.Have;
FORMAT Date_New MONYY7.;
Date_New=INPUT(Date_Orig,ANYDTDTE7.);
DROP Date_Orig;
RUN;
If you want to change to a different date format instead of 'MONYY7.', just put whatever date format you prefer in place of 'MONYY7.'.
Hope this helps.
data want(rename=(new_date=date));
length new_date 8.;
set have;
new_date = date;
format new_date monyy.;
run;
Hi VDD,
Thank you for the prompt reply. The solution you have provided is changing the character format into the required date format but not accurately.
Ex: 092009 has been converted into NOV2211, and the others have gone way into the future in the same way..
Can you help me with this?
Thank you.
/*********************/
/** SAMPLE DATASET **/
/*********************/
DATA WORK.Have;
FORMAT Date_Orig $30.;
INFORMAT Date_Orig $30.;
INPUT Date_Orig;
CARDS;
092009
102009
112009
122009
;
DATA WORK.Want (RENAME=(date_new=Date_Orig));
SET WORK.Have;
FORMAT Date_New MONYY7.;
Date_New=INPUT(Date_Orig,ANYDTDTE7.);
DROP Date_Orig;
RUN;
If you want to change to a different date format instead of 'MONYY7.', just put whatever date format you prefer in place of 'MONYY7.'.
Hope this helps.
Thank you Tsap. It works!!
You're welcome.
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!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.