BookmarkSubscribeRSS Feed
sas_sad
Calcite | Level 5

Hi,

 

I am calculating difference in days between diagnosis date and first lab test date using intck, but my code is not working right. Two of my date variables are numeric in MMDDYYYY format. This is a longitudinal data and I need to retrieve the difference between these two dates based on the very first lab test right after the diagnosis date. So, I have two issues here, one I am not sure how to use the intck function correctly and secondly how to select only the first labdate right after the diagnosis date. I have been asked to use only intck function, please keep in mind. This is a big data set with millions of records. 

 

This is my code and this is what I get:

 

sas_sad_1-1626845794140.png

sas_sad_0-1626845676506.png

 

Thanks,

 

17 REPLIES 17
ballardw
Super User

Does your log say anything about conversion of character to numeric values? You might see something like:

NOTE: Character values have been converted to numeric values at the places given by:
      (Line):(Column).

If so you do not have date variables at all, you have character variables that need to be turned into actual SAS values before using the INTCK function.

Or do you get something like

NOTE: Invalid argument to function INTCK('day',7152021,7212021) at line XX column YY.

That will happen you have simple numeric values that look like 07152021. They are also not date values.

We need to see which actual values you have to recommend which code is needed to create date values.

Examples converting character or numeric values that look like you say they might:

  data junk;
     x='07152021';
     y=7212021;
     /* character value*/
     newx=input(x,mmddyy10.);
     /*numeric value*/
     newy=input(put(y,z8.),mmddyy10.);
     format newx newy mmddyy10.;
     z = intck('day',newx,newy);
  run;

Please save yourself some trouble and don't make pictures of code or log results. Copy text from the editor or log and on the forum open a text box using the </> icon that appears above the message window. Then paste the code.

It is much easier to point out needed changes to code when it is text. If there are enough issues with code some of us will not take the time to retype log sections to make multiple minor changes.

 

Also, read the log. Really, it is very helpful. If you see something in the log you don't understand, copy the code and the messages from the log and paste into text box. The text box is important because the main message windows will reformat text and may mean that some of the diagnostics that SAS supplies will not appear correctly.

 

When unexpected results, such as a bunch of missing values are generated one of the first things is to make sure that the variables and the values you are using are appropriate for the function. In the case of date related functions you need 1) numeric variables and 2) in specific ranges. SAS dates are the number of days since 1 Jan 1960. So if you have a number like 07152021 that would the year 21,705. For some likely very good reasons none of the SAS date functions work with dates past year 20,000. Proc contents will help. If the variable type is character it is pretty obvious what needs to be done. If the type is numeric but the format is something like BEST12. or F12. then you have plain number and seldom will it resolve with date functions.

 

https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/... has a PDF with much information about dates.

 

It is best to p

sas_sad
Calcite | Level 5
Thank you, here is the log when I run this code. My dates are numeric in MMDDYYY format like 02/05/2019. Should I change it to sas dates and remove the missing dates as the log says?

data hiv;
no_of_days = intck ('DAY',hivdiag_date,labdate);
run;

NOTE: Variable hivdiag_date is uninitialized.
NOTE: Variable labdate is uninitialized.
NOTE: Missing values were generated as a result of performing an operation on missing values.
Each place is given by: (Number of times) at (Line):(Column).
1 at 51:14
NOTE: The data set WORK.HIV has 1 observations and 3 variables.


sas_sad
Calcite | Level 5
 
sas_sad
Calcite | Level 5
I used the set statement but still gives the same result.
PaigeMiller
Diamond | Level 26

@sas_sad wrote:
I used the set statement but still gives the same result.

Okay, @sas_sad , here's an important concept. When you have code that doesn't work, SHOW US the LOG so we can see the code you used, as it appears in the LOG, plus all ERRORs, WARNINGs and NOTEs. Do not pick and choose parts of the log to show us, show us ALL of it, every single character of the LOG, for the code in question. (This should be done every single time from now on, without us asking to see the LOG)

 

Another important concept: If you tell us something doesn't work, and provide no other information, we cannot help you. 

--
Paige Miller
andreas_lds
Jade | Level 19

Problem: Your data step has no set-statement.

sas_sad
Calcite | Level 5
data hiv;
no_of_days = intck ('DAY',hivdiag_date,labdate);
run;

NOTE: Variable hivdiag_date is uninitialized.
NOTE: Variable labdate is uninitialized.
NOTE: Missing values were generated as a result of performing an operation on missing values.
      Each place is given by: (Number of times) at (Line):(Column).
      1 at 51:14
NOTE: The data set WORK.HIV has 1 observations and 3 variables.
NOTE: DATA statement used (Total process time):
      real time           0.08 seconds
      cpu time            0.01 seconds
PaigeMiller
Diamond | Level 26

@sas_sad 

 

Two people have pointed out you have no SET statement, so your variables hivdiag_date and labdate don't have values. You need to fix that.

--
Paige Miller
sas_sad
Calcite | Level 5
I did, still gives the same result. Does not give any result for the difference in days.

Tom
Super User Tom
Super User

@sas_sad wrote:
I did, still gives the same result. Does not give any result for the difference in days.


But you haven't shown the log from any runs that actually used any data.  

Note that if your variables are dates (the number of days since 1960) then you can get the difference in days by simple subtraction.

data want;
  set have;
  diff = date1 - date2 ;
run;

 

sas_sad
Calcite | Level 5
I posted my log above, I used the set statement, still nothing.
PaigeMiller
Diamond | Level 26

@sas_sad wrote:
I posted my log above, I used the set statement, still nothing.

As before, saying it doesn't work and NOT EXPLAINING doesn't help us and doesn't help us help you.

 

What do you mean by "still nothing". Can you SHOW US what you see that indicates "still nothing"?

--
Paige Miller
sas_sad
Calcite | Level 5
data hiv1;
set hiv;
no_of_days = intck ('DAY',hivdiag_date,labdate);
run;

NOTE: Missing values were generated as a result of performing an operation on missing values.
      Each place is given by: (Number of times) at (Line):(Column).
      2603 at 60:14
NOTE: There were 2995385 observations read from the data set WORK.HIV.
NOTE: The data set WORK.HIV1 has 2995385 observations and 364 variables.
NOTE: DATA statement used (Total process time):
      real time           21.77 seconds
      cpu time            0.85 seconds

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 17 replies
  • 2570 views
  • 2 likes
  • 6 in conversation