SAS Procedures

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

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

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

There's a format for that 😉

 

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;

 

View solution in original post

2 REPLIES 2
Reeza
Super User

There's a format for that 😉

 

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;

 

Jani_Pretorius
Calcite | Level 5

You can use the following format to convert a date to YYMM or YYYYMM. For example: 12-03-2018 to 201803:

 

put(r.MyDate, yymmn6.) as MyDateFormatted

See this link for more details:

http://support.sas.com/documentation/cdl/en/fedsqlref/67364/HTML/default/viewer.htm#n1d48aw39lluo9n1...

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 62081 views
  • 3 likes
  • 3 in conversation