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

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

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

View all other training opportunities.

Discussion stats
  • 2 replies
  • 625 views
  • 0 likes
  • 3 in conversation