Help using Base SAS procedures

Error in Dates

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 16
Accepted Solution

Error in Dates

DATA Logins;

SET SASUSER.NTBPLRC;

  DOB_TEMP = TRANWRD(DOB, "0:0:0. 0", "");

  DOB = MDY(SCAN(DOB_TEMP,2,"-"), SCAN(DOB_TEMP,3,"-"), SCAN(DOB_TEMP, 1,"-"));

  FORMAT DOB DATE9.;

RUN;

I am getting the following error:

DATA Logins;

16         SET SASUSER.NTBPLRC;

17         DOB_TEMP = TRANWRD(DOB, "0:0:0. 0", "");

18         DOB = MDY(SCAN(DOB_TEMP,2,"-"), SCAN(DOB_TEMP,3,"-"), SCAN(DOB_TEMP, 1,"-"));

19         FORMAT DOB DATE9.;

                        ______

                        484

NOTE 484-185: Format $DATE was not found or could not be loaded.

Please help to solve the issue.


Accepted Solutions
Solution
‎03-05-2014 10:02 AM
Super User
Posts: 17,829

Re: Error in Dates

You can't change a variable type from character to numeric in the same datastep. So you already have a variable DOB that's character so you need to change that somehow, or rename it before you import it.

Have you tried an input function instead?

DATA Logins;

SET SASUSER.NTBPLRC (rename=dob=_dob);

  DOB_TEMP = TRANWRD(_DOB, "0:0:0. 0", "");

  DOB = MDY(SCAN(DOB_TEMP,2,"-"), SCAN(DOB_TEMP,3,"-"), SCAN(DOB_TEMP, 1,"-"));

dob2=datepart(input(_dob, anydtdtm.));

  FORMAT DOB dob2 DATE9. ;

RUN;

View solution in original post


All Replies
Solution
‎03-05-2014 10:02 AM
Super User
Posts: 17,829

Re: Error in Dates

You can't change a variable type from character to numeric in the same datastep. So you already have a variable DOB that's character so you need to change that somehow, or rename it before you import it.

Have you tried an input function instead?

DATA Logins;

SET SASUSER.NTBPLRC (rename=dob=_dob);

  DOB_TEMP = TRANWRD(_DOB, "0:0:0. 0", "");

  DOB = MDY(SCAN(DOB_TEMP,2,"-"), SCAN(DOB_TEMP,3,"-"), SCAN(DOB_TEMP, 1,"-"));

dob2=datepart(input(_dob, anydtdtm.));

  FORMAT DOB dob2 DATE9. ;

RUN;

Occasional Contributor
Posts: 16

Re: Error in Dates

Oh yes, Its working......

thanks alot Smiley Happy

Occasional Contributor
Posts: 16

Re: Error in Dates

but again why do I need to rename it?

Super User
Posts: 17,829

Re: Error in Dates

Because DOB is a character variable. You can't switch it to a date/numeric variable. You either need to give your input or output variable a new name.

Occasional Contributor
Posts: 16

Re: Error in Dates

DATA Logins;

SET SASUSER.NTBPLRC (rename=dob=_dob);

  DOB_TEMP = TRANWRD(_DOB, "0:0:0. 0", "");

  DOB = MDY(SCAN(DOB_TEMP,2,"-"), SCAN(DOB_TEMP,3,"-"), SCAN(DOB_TEMP, 1,"-"));

  dob2=datepart(input(_dob, anydtdtm.));

  FORMAT DOB dob2 DATE9. ;

  Age = Round((DATE() - DOB)/365,0);

  

RUN;

WARNING: Limit set by ERRORS= option reached.  Further errors of this type will not be printed.

It was working perfectly and giving results if I dont use "Round()"

please help

Super User
Posts: 17,829

Re: Error in Dates

New question, new thread please.

1. You only need one of the the two calculations above, DOB or DOB2

2. If you're trying to calculate age, there are better ways. Search on here for the ideal way to calculate age.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 1214 views
  • 0 likes
  • 2 in conversation