PUT converts the variable to a character variable.
Your question is a bit unclear. I'm not sure what you're starting with and what you're trying to achieve in the end. SAS dates are counted as the number of days from Jan 1, 1960 and then formats are applied to show the date in the desired appearance.
My my guess is although you say there's no error it's likely you have NOTES regarding a conversion of,type from character to numeric. SAS may have done the conversion for you when you did the subtraction.
PUT converts the variable to a character variable.
Your question is a bit unclear. I'm not sure what you're starting with and what you're trying to achieve in the end. SAS dates are counted as the number of days from Jan 1, 1960 and then formats are applied to show the date in the desired appearance.
My my guess is although you say there's no error it's likely you have NOTES regarding a conversion of,type from character to numeric. SAS may have done the conversion for you when you did the subtraction.
I just set up an example data set and ran your code:
data telecom;
input svc_start_dt :mmddyy10. svc_end_dt :mmddyy10.;
format svc_start_dt svc_end_dt mmddyy10.;
cards;
08/09/2001 04/09/2003
10/30/2001 03/26/2002
;
run;
data telecom_service;
set telecom;
st_dt = put(svc_start_dt,10.);
put st_dt= yymmdd10.;
end_dt = put(svc_end_dt,10.);
put end_dt= yymmdd10.;
duration = end_dt - st_dt;
run;
This is the log:
16 data telecom; 17 input svc_start_dt :mmddyy10. svc_end_dt :mmddyy10.; 18 format svc_start_dt svc_end_dt mmddyy10.; 19 cards; NOTE: The data set WORK.TELECOM has 2 observations and 2 variables. NOTE: DATA statement used (Total process time): real time 0.02 seconds cpu time 0.00 seconds 22 ; 23 run; 24 25 data telecom_service; 26 set telecom; 27 st_dt = put(svc_start_dt,10.); 28 put st_dt= yymmdd10.; _________ 484 NOTE 484-185: Format $YYMMDD was not found or could not be loaded. 29 end_dt = put(svc_end_dt,10.); 30 put end_dt= yymmdd10.; _________ 484 NOTE 484-185: Format $YYMMDD was not found or could not be loaded. 31 duration = end_dt - st_dt; 32 run; NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column). 31:12 31:21 st_dt=15196 end_dt=15804 st_dt=15278 end_dt=15425 NOTE: There were 2 observations read from the data set WORK.TELECOM. 2 The SAS System 08:48 Monday, December 12, 2016 NOTE: The data set WORK.TELECOM_SERVICE has 2 observations and 5 variables. NOTE: DATA statement used (Total process time): real time 0.10 seconds cpu time 0.01 seconds
You can clearly see the NOTE messages caused by trying to do date formatting on character variables. My Enterprise Guide interprets those messages already as errors (red "x" on the program icon).
Note that the result (duration) is numeric as intended, since it is created with a calculation.
You can completely omit the conversion, and simply do:
data telecom_service;
set telecom;
duration = svc_end_dt - svc_start_dt;
run;
which gives you the same result, but without problems in the log.
It's difficult to believe that your original dates are numeric, when they print in two different formats. If they are numeric, you already have a simple formula for duration that you can apply, without any formats or transformations. But I would double-check what is in those variables first by running a PROC CONTENTS.
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.
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.