Write and run SAS programs in your web browser

Number Format to Date Format

Reply
Occasional Contributor
Posts: 5

Number Format to Date Format

Hi,

 

How can I transofm the number 201403 into the date 03/2014 on SAS?

 

Thank you 

Super User
Posts: 3,100

Re: Number Format to Date Format

There isn't a SAS format for what you want but you can create your own (untested):

 

proc format;
  picture MyDateFmt low-high='%0m/%y' (datatype=date);
run;

data test;
  datenum = 201403;
  MyDate = input(put(datenum * 100 + 1, 8.), yymmdd8.);
  format MyDate MyDateFmt.;
  put _all_;
run;
Super Contributor
Posts: 275

Re: Number Format to Date Format

data _null_;
date=201403;
_date=input(put(date,6.),yymmn6.);
format _date mmyys7.;
put _all_;
run;

SAS Super FREQ
Posts: 8,739

Re: Number Format to Date Format

Hi:
This post is remarkably similar (uses the same number as this posting https://communities.sas.com/t5/Base-SAS-Programming/Importing-sas7bdat-file/m-p/370282#M88434) 201403 as an example of a number that is a date variable.

Homework?? Another possible answer was posted in the other forum. Also posted with a longer explanation of how date variables work.

cynthia
Ask a Question
Discussion stats
  • 3 replies
  • 201 views
  • 2 likes
  • 4 in conversation