Hi,
I'm using the following code to calculate time difference between 2 variables:
/* create new columns to calculate time differences and convert Time1 Time2 Time3 Time4 variables (columns have character values) */
data Ttimeslots2;
set Ttimeslots;
NewDraw1diff = input(Time1,time8.);
NewDraw2diff = input(Time2,time8.);
NewDraw3diff = input(Time3,time8.);
NewDraw4diff = input(Time4,time8.);
format NewDraw1diff NewDraw2diff NewDraw3diff NewDraw4diff time8.;
run;
I have checked the variables attributes and the variables NewDraw1diff, NewDraw2diff, NewDraw3diff, and NewDraw4diff have time8. as format .
Due to as error in variable Time1 in the original dataset, I have to correct the values in NewDraw1diff if a given condition is met based on the following code:
data Ttimeslots3;
set Ttimeslots2;
if index(SP,'18C') then NewDraw1diff=Draw1-EDTIME;
format NewDraw1diff time8.;
run;
Both Draw1 and EDTIME have time8. as format and informat and some rows have missing values.
when I run the code above I get the following log messages:
NOTE: Variable Draw1 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).
56 at 400:58
NOTE: There were 1890 observations read from the data set TTIMESLOTS2.
NOTE: The data set TTIMESLOTS3 has 1890 observations and 20 variables.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.01 seconds
It seems like the if statement is not property working and I can't figure out why.
Does anyone know what's wrong with my code?
NOTE: Variable Draw1 is uninitialized.
means that variable Draw1 is not on your input dataset. Did you actually want to use time1? If yes, and the conversion in your first step worked, then your calculation can't work, as time1 would be of type character. Please post the whole log from these two steps (including all the code!) into a window opened with the </> button.
Please post the whole log from these two steps (including all the code!) into a window opened with the </> button.
I will not ask a third time.
@ACLAN wrote:
Can you please explain why the calculation in step 2 can't work ? the NewDraw1 format was defined as time8. and the Draw1 and EDTIME have the same format.
Calculations depend on the data. Without actual data there really isn't any way to be sure what is going on.
Provide example data in the form of a data step.
Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the </> icon or attached as text to show exactly what you have and that we can test code against. The code box is important as the message windows will reformat text possibly rendering the data step code invalid.
Provide enough examples that duplicate the "problem" cases and some non-problem if possible.
@ballardw Thank you for helping by given the link to the example on who to reproduce our data. This is really good for people like me who are just starting to use SAS.
I found the problem. Draw1 was not used because it has a space in the variable name (Draw 1). I changed the code to Draw_1 and not it works. I'm new to SAS and I had no idea that this can be an issue.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.