BookmarkSubscribeRSS Feed
Q1983
Lapis Lazuli | Level 10

data uw_hist_1;

set uw_hist;

decision_date1=datepart(decision_date);

decision_date2=datepart(decision_date);

format decision_date1 mmddyy10.;

put decision_date2 hhmm8.2;

run;

 

LNKEY

DECISION_DATE

decision_date1

decision_date2

4001532474

24Sep2016 7:24:00.000

09/24/2016

20721

4001474487

29Sep2016 16:52:00.000

09/29/2016

20726

4001474487

27Oct2016 18:11:00.000

10/27/2016

20754

4001532474

28Nov2016 14:24:00.000

11/28/2016

20786

 

I want to display the time for decision_date2 in time format like this I used hhmm8.2 however I get different results in decision_date2.  How can I obtain the time format and would it maintain once I exported, especially in ODS whcih is the ultimate output

2 REPLIES 2
ballardw
Super User

By any chance do you want the TIMEPART of decision_date for the second value?

 

decision_date2=TIMEpart(decision_date);

Times and Datetimes in SAS are seconds, Dates are days. You will not have much luck displaying DATES with a TIME value.

 

If you permanently attach a format to a variable that will generally be the default for most output that does not involve a calculation (sas as mean in proc means/summary output for instance). Or specify the format in procedure generating the output such as Proc print. One of the nice things with the SAS formats is the ability to override them as needed.

 

 

By the way, one of my pet peeves is calling datetime values a date, or time values a date or dates a time/datetime. While other data systems may not care the measurement differences in SAS make it important.  Proper use of functions and or formats requires that understanding. Both values are numeric and numeric functions generally don't care what you give them. Consider:

 

data _null_;
   file print;
   x="10:15:23"t;
   y=month(x);
   put y=  ;
run;

I declared a TIME variable and them applied a DATE function. What would the result for Y actually mean if it appears in your output?

 

Shmuel
Garnet | Level 18

Your code:

data uw_hist_1;
set uw_hist;
decision_date1=datepart(decision_date);
decision_date2=datepart(decision_date);  /* Didn'y you mean: timepart ? */
format decision_date1 mmddyy10.;
put decision_date2 hhmm8.2;
run;

What is the logic of subsetin datepart and displaying it with hhmm format ?

 

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!

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.

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
  • 2 replies
  • 729 views
  • 0 likes
  • 3 in conversation