BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
kartheekm9
Calcite | Level 5

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?

1 ACCEPTED SOLUTION

Accepted Solutions
tsap
Pyrite | Level 9


/*********************/
/**	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.

View solution in original post

5 REPLIES 5
VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

data want(rename=(new_date=date));
length new_date 8.;
set have;
new_date = date;
format new_date monyy.;
run;

kartheekm9
Calcite | Level 5

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.

 

tsap
Pyrite | Level 9


/*********************/
/**	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.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 5 replies
  • 587 views
  • 0 likes
  • 3 in conversation