+ Reply to Thread
Results 1 to 6 of 6

Thread: problem generating age

  1. #1
    Fortran must die
    Points: 48,197, Level: 100
    Level completed: 0%, Points required for next Level: 0
    noetsi's Avatar
    Posts
    6,434
    Thanks
    674
    Thanked 909 Times in 868 Posts

    problem generating age




    I have a function I have used for years successfully to calculate age. It's

    ((floor ((intck('month',

    T1.DATEOFBIRTH,

    T1.DATEBEGIN_AT_CLO) - (day (T1.DATEBEGIN_AT_CLO) < day (T1.DATEOFBIRTH)))/12) )
    )

    Where I want to calculate age at datebegin_At_Clo .The problem here is that I am starting with a date stored as a text field (I did not generate it the federal government does and I do not know how they formatted it except that it is a string).

    It is of the form '19761026' where the first four digits are the year, the next two the month and the next two the days.

    I ran

    PROC SQL;
    CREATE TABLE WORK.QUERY_FOR_Q16 AS
    SELECT t1.DateOfBirth,
    t1.ClosureDate,
    /* DOB */
    (INPUT(t1.DateOfBirth, yyyymmdd10.)) LABEL="DOB" AS DOB,
    /* CD */
    (INPUT(t1.ClosureDate, yyyymmdd10.)) LABEL="CD" AS CD
    FROM WORK.Q16 t1;
    QUIT;

    and it appears to generate a number fine. However when I use the new fields (DOB and CD) in the age function above I get no results (not errors just no results).

    That is I get nothing when I run

    PROC SQL;
    CREATE TABLE WORK.QUERY_FOR_Q16_0000 AS
    SELECT t1.DateOfBirth,
    t1.ClosureDate,
    /* Age */
    (((floor ((intck('month',

    T1.Dob,

    T1.cd) - (day (T1.cd) < day (T1.Dob)))/12) )
    )
    ) LABEL="Age" AS Age
    FROM WORK.QUERY_FOR_Q16 t1;
    QUIT;
    Last edited by noetsi; 04-14-2017 at 05:32 PM.
    "The difference between genius and stupidity is that genius has its limits."

  2. #2
    Omega Contributor
    Points: 34,329, Level: 100
    Level completed: 0%, Points required for next Level: 0
    hlsmith's Avatar
    Location
    Not Ames, IA
    Posts
    6,589
    Thanks
    374
    Thanked 1,105 Times in 1,068 Posts

    Re: problem generating age

    I will start simple, I am guessing your proc has a "p" on it in the real code?
    Stop cowardice, ban guns!

  3. #3
    Fortran must die
    Points: 48,197, Level: 100
    Level completed: 0%, Points required for next Level: 0
    noetsi's Avatar
    Posts
    6,434
    Thanks
    674
    Thanked 909 Times in 868 Posts

    Re: problem generating age

    Yes it does. This was done in EG so typos like that reflect me copying wrong. The system does it automatically. I think SAS is having problems with the fact that the date is stored as 'yyyymmdd' in the original text string. As in '19761026' I converted it to a number correctly, but it does not seem to be able to make sense of that number.
    "The difference between genius and stupidity is that genius has its limits."

  4. #4
    Points: 3,124, Level: 34
    Level completed: 50%, Points required for next Level: 76

    Location
    Raleigh,NC
    Posts
    80
    Thanks
    0
    Thanked 9 Times in 9 Posts

    Re: problem generating age

    why is there a space between; WORK.QUERY_FOR_Q16 t1 - should the t1 be there?

  5. #5
    Fortran must die
    Points: 48,197, Level: 100
    Level completed: 0%, Points required for next Level: 0
    noetsi's Avatar
    Posts
    6,434
    Thanks
    674
    Thanked 909 Times in 868 Posts

    Re: problem generating age

    Quote Originally Posted by Jrb599 View Post
    why is there a space between; WORK.QUERY_FOR_Q16 t1 - should the t1 be there?
    Yes it is a table alias
    "The difference between genius and stupidity is that genius has its limits."

  6. #6
    Fortran must die
    Points: 48,197, Level: 100
    Level completed: 0%, Points required for next Level: 0
    noetsi's Avatar
    Posts
    6,434
    Thanks
    674
    Thanked 909 Times in 868 Posts

    Re: problem generating age


    This code, followed by the age calculation, works. I am not sure why my other code failed but it does not matter.

    Data TEST15b;
    set work.closures2;
    Dob = Input(dateofbirth, Yymmdd10.);
    cd = Input(closuredate, Yymmdd10.);
    Run;
    "The difference between genius and stupidity is that genius has its limits."

+ Reply to Thread

           




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts






Advertise on Talk Stats