My current date character value is stored as ddmmmyyyy so I used date9. when changing it to the numeric value. The problem is that when I look at my data set the value for that variable is the SAS date. I tried using "format date date9.;" to convert the SAS date to Date 9. but I am getting the following error message: ERROR 48-59: The format $DATE was not found or could not be loaded.
What am I doing wrong? Thanks.
My code:
format date date9.;
datel=input(date,date9.);
totday=intck('day',daterand,date);
example of data:
Date Subject # Visit # Randomization date
01May1996 1 1 15Jan1996
25July1996 1 2 15Jan1996
15Aug1995 2 1 20Mar1995
In my example:
data want; set have (rename=(date=char_date)); date=input(char_date,date9.); format date date9.; run;
I first rename the variable you already have - in the set statement - so no variable named date is in the data at that moment. Now when I use the assingment date=, this creates a new variable called date - which as I have not specified a length/type, defaults to numeric 8. Into this new variable I then put the result of the input() function, and its this new variable which is formatted.
Post example test data as a datastep, and show what the output should look like. If you have a character field, then you can't just format it to date as it will still be a chacter variable. Do something like:
data want; set have (rename=(date=char_date)); date=input(char_date,date9.); format date date9.; run;
So your creating a numeric variable to hold a numeric date.
Well, the input function returns a number - which is the number of days since a certain date which is how SAS keeps dates. If you have:
<character variable>=112344;
format <character variable> <numeric format>;
Its not going to work. So you want the variable that recieves the number from the input() function to be number, so it can be formatted using the numeric format date9.
This should help on the dataset:
In my example:
data want; set have (rename=(date=char_date)); date=input(char_date,date9.); format date date9.; run;
I first rename the variable you already have - in the set statement - so no variable named date is in the data at that moment. Now when I use the assingment date=, this creates a new variable called date - which as I have not specified a length/type, defaults to numeric 8. Into this new variable I then put the result of the input() function, and its this new variable which is formatted.
You posted this code:
datel=input(date,date9.); totday=intck('day',daterand,date);
BY ANY chance did you try to use the DATEL(numeric) variable instead of DATE(character) in the INTCK call
@PaulaC wrote:
that was a typo. my input statement code was: date=input(date,date9.); but I got an error message when used format date date9. When I changed the input to daten=input(date,date9.) and format daten date9. then the error message disappeared and a new variable daten was created.
To minimize typo issues, and especially when you run code with an error, go to the SAS log and copy the code with the error and diagnostic messages. Then paste into a code box using the {i} icon. The code box will retain the formatting of the orginal log and the error message often has an _ indicating the exact place SAS encountered the trigger for the message. The forum main text boxes actually reformat your pasted text and loses information like where SAS placed that underscore.
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.