BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
libokj
Fluorite | Level 6
Finally, I understand what's happening behind the scene when SAS overwrites a variable in a pre-existing dataset. Many thanks!
libokj
Fluorite | Level 6
Thank you! Precision was indeed the problem. I'm new to SAS and quite unfamiliar with its data structures and features. Specifying length in the data step for edate and ddate before the rewrite solved the problem.
Tom
Super User Tom
Super User

@libokj wrote:
Thank you! Precision was indeed the problem. I'm new to SAS and quite unfamiliar with its data structures and features. Specifying length in the data step for edate and ddate before the rewrite solved the problem.

A lot of uses are confused by LENGTH.  The conflate the LENGTH (number of bytes stored in the SAS datasets) with the WIDTH of the format used to DISPLAY the value as text.

libokj
Fluorite | Level 6

Thank you all for such quick replies. It's my first time posting here, and I have already found the SAS Community so friendly and helpful.

I did leave out some important details:

  1. edate and ddate are numeric (integers). They represent days elapsed from day zero in a clinical trial, so simply 0, 1, 2, etc.
  2. I was trying to transform these integer "dates" into actual date objects by adding the date for the day zero (7 May 2000), which I believe in SAS is equivalent to a numeric.

By reading @FreelanceReinh's post, I realized that this could be a problem with rounding. I'm new to SAS and found it strange that SAS "does not" differentiate between int and float types and instead only has "numeric". Thanks to your post, I've learned that there are ways to debug SAS like in other languages. 

Tom
Super User Tom
Super User

SAS datasets have two data types.  Fixed length character strings and floating point numbers.

The DATE formats will ignore fractions of a day.

822   data _null_;
823     now=today();
824     do offset=0,1,-1,-0.5,+0.5 ;
825       new=now+offset;
826       put offset= new= new= date9.;
827     end;
828   run;

offset=0 new=22749 new=14APR2022
offset=1 new=22750 new=15APR2022
offset=-1 new=22748 new=13APR2022
offset=-0.5 new=22748.5 new=13APR2022
offset=0.5 new=22749.5 new=14APR2022
libokj
Fluorite | Level 6
Thank you for the information. I was aware of this feature. I did try to output the variables in HEX as @FreelanceReinhard suggested, and they were correct in the PUT output, but in the saved dataset the dates still have the same problem.