Date change from YYYYMMDD to MM/DD/YYYY
Posted: 02 March 2013 10:43 AM   [ Ignore ]
Newbie
Rank
Total Posts:  10
Joined  2012-03-03

Hi,

I am stuck at this problem. Is there any code to convert from YYYYMMDD to MM/DD/YYYY? Thank you so much.

Profile
 
 
Posted: 03 March 2013 09:09 AM   [ Ignore ]   [ # 1 ]
Administrator
Avatar
RankRankRankRank
Total Posts:  901
Joined  2011-09-19

hi SamLe,

Is the variable stored as a character variable, or a date variable. You can tell by double-clicking in the column name (or rightclick on the dataset in the explorer and select ‘view columns’.

If the variable is a character (type text), you would need to manipulate the string. Take the substring of positions 1-4 (the year), 5-6 (month) and 7-8 (day) and create a date variable with function mdy.

If the variable is a date, things are easier. A date is stored as a number in memory, and can be displayed using different formats. In that case, you add a ‘format’ statement in a datastep (no other calculations/transformations are needed).

See here for examples: upport.sas.com/documentation/cdl/en/etsug/60372/HTML/default/viewer.htm#etsug_tsdata_sect008.htm

best regards,

Joost

 Signature 

To reply/post new questions: Please use the group WRDS/SAS on Google Groups! http://groups.google.com/d/forum/wrdssas

Profile