Thursday, October 30, 2008

How to convert a SAS date to a character variable

/***************************************************************************//*
Title: Convert a SAS date to a character variable *// *
*//* Goal: Use the PUT function to create a character variable from *//*
a SAS date. *//* *//***************************************************************************/

data one;
input sasdate :mmddyy6.;
datalines;
010199;
run;

data two;
set one;
chardate=put(sasdate,mmddyy6.);
run;

/* RESULTS */

Obs sasdate chardate
1 14245 010199


Source: ftp://ftp.sas.com/techsup/download/sample/datastep/convertchar.html

2 comments:

  1. Fine, but what about a date like 01011999, which there doesn't appear to be a date format for?

    ReplyDelete
  2. you use mmddyy8. format instead of mmddyy6.

    ReplyDelete

Learn how to view SAS dataset labels without opening the dataset directly in a SAS session. Easy methods and examples included!

Quick Tip: See SAS Dataset Labels Without Opening the Data Quick Tip: See SAS Dataset Labels With...