BookmarkSubscribeRSS Feed
RPYee
Quartz | Level 8

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

 

___________________________________
The fact that I ask for help simply means I am inexperienced and under-educated. Please don't assume I am incompetent and uneducated.
2 REPLIES 2
Tom
Super User Tom
Super User

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;

image.png

PaigeMiller
Diamond | Level 26

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?

--
Paige Miller

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 2664 views
  • 0 likes
  • 3 in conversation