BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ballardw
Super User

Or possibly leave the datetime value alone and use a format like DTMONYY7. when you need to use the date time grouped at month level.

Reeza
Super User

Here's a sample that demonstrates the issue:

 

data sample;
date = dhms(today(), 11, 15, 0); /*Datetime variable*/
dtdate =datepart(date); /*Date variable*/

put date = datetime21.;
put date = dtdate9.;
put date = dtmonyy7.;
put dtdate = date9.;
put dtdate = monyy7.;
run;

 

And the output:

 

date=20JAN2016:11:15:00
date=20JAN2016
date=JAN2016
dtdate=20JAN2016
dtdate=JAN2016
NOTE: The data set WORK.SAMPLE has 1 observations and 2 variables.
NOTE: DATA statement used (Total process time):
      real time           0.03 seconds
      cpu time            0.01 seconds

 

Steelers_In_DC
Barite | Level 11

You don't specify if you want the output to be a date or character.  Here is a solution for both:

 

data have;
infile cards dsd;
informat date1 date9.;
format date1 date9.;
input date1;
cards;
31Dec2015
;run;

data want;
set have;
date2 = date1;
format date2 monyy7.;
date3=input(put(date2,monyy7.),$7.);
run;

apolitical
Obsidian | Level 7

Thank you all for helping out. It turns out proc sql has to interpret a date variable by the specific day, no matter how hard you try to hide it by using format. The solution is either to use proc means to get aggregates, or turn date variable into character variables. The former proved to be more natural, as it retains the chronological order of months.

 

Thank you so much.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 18 replies
  • 138315 views
  • 5 likes
  • 7 in conversation