Help using Base SAS procedures

Need to format date/time as YYYYMM

Reply
New User
Posts: 1

Need to format date/time as YYYYMM

[ Edited ]

I looking to format a date/time field as an interger in the format of YYYYMM. Below works, but I cannot figure out how to remove the day part (DD). Thanks.

 

input(put(datepart(r.MyDate),yymmddn8.),8.) as MyDateFormatted format=8.

 

Example:

 

MyDate=10MAR2017:13:29:57.000

Need=201703 as numeric

 

 

Super User
Posts: 19,878

Re: Need to format date/time as YYYYMM

Posted in reply to mariearev

There's a format for that Smiley Wink

 

YYMMN6 Format, either apply the format or use PUT() with DATEPART(). 

 

 

data test;
 dt=dhms('01Jan2017'd, 5, 2, 20);
 format dt datetime20.;
 
 date_formatted=datepart(dt);
 format date_formatted yymmn6.;
 
 x=put(datepart(dt), yymmn6.);
 y=input(x, 8.);
run;

ods select variables;

proc contents data=test;
run;

proc print data=test;
run;

 

Ask a Question
Discussion stats
  • 1 reply
  • 1834 views
  • 2 likes
  • 2 in conversation