Reputation: 61
I am trying to find the interval in terms of weeks between two $4.00
variables in date9 format.
The working example has two variable with dates formatted like 18JAN2017 and 25FEB2017. I want to create a third variable that shows the amount of weeks that fit into the interval between these dates within an observation/by subject ID.
I have tried:
data test1;
set inputs1;
difference = intck('week',input(date1,date9.),input(date2,date9.));
run;
This code returns missing and $0 values. I expected a new variable named difference
showing the amount of weeks between the two dates by observation.
Is this a matter of formatting or syntax, or is intck
not able to deal with variables?
Upvotes: 0
Views: 1028
Reputation: 27498
A format tells SAS how to render a value when it is viewed. The format does not change the underlying value. So if variable date1
is formatted date9.
that means the variable is numeric, taking on values that represent date values in the SAS date epoch (0 is 01-JAN-1960). As such, the numeric value should not be passed to INPUT
.
A character variable can have a value whose construct is ddMONyyyy
. That variable would not be formatted date9.
The character value would be the formatted representation of a date value, and would have to be passed through INPUT
to get the numeric value corresponding the date in SAS epoch.
intck
most certainly can deal with variables -- in fact it deals with any expression that evaluates (implicitly or explicitly) to a number. A string containing a formatted date representation cannot be implicitly evaluated to a SAS number, it would have to pass through input
.
A formatted numeric passed through INPUT
is just not correct. The numeric value would go into the INPUT
function implicitly unformatted and converted to a string and the 'digits' would be parsed according to the specified informat, and fail doing so.
Here is some sample code exploring the above narrative:
data _null_;
today = today();
tomorrow = today + 1;
diff = intck ('day', today, tomorrow);
put today tomorrow diff;
date1num_as_char = '21560';
date2num_as_char = '21561';
diff = intck ('day', date1num_as_char, date2num_as_char);
put date1num_as_char date2num_as_char diff;
date1_as_string = '11JAN2019'; * not a SAS date value, is a date representation;
date2_as_string = '12JAN2019';
diff = intck ('day', date1_as_string, date2_as_string);
put date1_as_string date2_as_string diff;
now = today();
format now date9.;
put now=;
now_through_input = input(now,date9.); * just wrong;
put now_through_input=;
run;
Upvotes: 1