I have two types of events (Event_A , Event_B) and their associated timestamps. There can be multiple timestamps for the same event. I want to check the event for each row and create a computed field related to the timestamp field. My "CASE" statement was originally:
CASE
WHEN event = EVENT_A
THEN timestamp
ELSE ' '
END
This would give me an error that the second datatype doesn't match the first. So, I changed it to:
CASE
WHEN event = EVENT_A
THEN timestamp
END
This works fine, but it puts a period when the test is false. Is there a way to just leave the result blank? I'll have two computed fields, EVENT_A_TMPSTP and EVENT_B_TMSTP. I'll then find the minimum of each occurrence and move forward with those results. I'm not sure how the period will play into this next step...
Thanks for any help!!
RPYee
You cannot store a character string, like a space, into a numeric variable.
But you can change the way numeric missing values are printed by using the MISSING option.
Example:
data test;
row=1;
now=datetime();
format now datetime19.;
output;
row=2;
now=.;
output;
run;
proc print data=test;
run;
options missing=' ';
proc print data=test;
run;
I'll have two computed fields, EVENT_A_TMPSTP and EVENT_B_TMSTP. I'll then find the minimum of each occurrence and move forward with those results. I'm not sure how the period will play into this next step...
I'm not sure how the blank will play into this next step. But it would be better, in my mind, to leave the missing there because for all arithmetic and functions and boolean comparisons, we know exactly how SAS will handle the missing value. You can use the MIN function, for example, and this will return the minimum of the non-missing values.
min(event_a_tmpstp,event_b_tmstp)
So, when you are finding the minimum, and one of the two values is missing, what do YOU want as the result?
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.