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
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?
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 ?
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.
Ready to level-up your skills? Choose your own adventure.