09-26-2014 07:51 AM
I have base dataset with date field 4 byte. I want to append records to it which has the date field 8 byte.
can anyone help me how to convert 8 byte number to 4 byte which will hold the same date.
09-26-2014 08:22 AM
Please clarify what you mean with some test data. As far as I am aware date variables are always length=8 as they are numeric counts of days since a certain date. Bytes should not come into it.
09-26-2014 09:31 AM
Why did you want convert it from 8 to 4 ? Why not just use 8 as simple as it was ? Since you are appending a table at bottom of another table , sql is going to convert them all into 8 . Wouldn't it be better ?
create table want as
select * from one
union all corr
select * from two ;
If you have to convert 8 into 4 ,then you have to make another variable which has length of 4 .
length new 4 ;
But that might be losing exact float .
09-26-2014 09:47 AM
You probably do not need to do anything. SAS will just throw away the extra bits of precision. And dates, since they are just the number of days, do not need that extra precision.
Let's assume you have two tables OLD and NEW and you want to add the records from NEW onto those in OLD.
If you use a datastep to make a new dataset then the lengths will be set by what length is defined first.
data master ; set old new ; run;
If you use PROC APPEND then the data will be appended into the OLD table and so of course will have the same length.
09-26-2014 12:08 PM
The only reason for that issue is proc append usage. Base SAS(R) 9.4 Procedures Guide, Third Edition
Using proc append is avoiding all the IO overhead of other approaches by just modifying growing the base dataset on dasd in place.
The force option solve some of the differneces.
The best way of creating the new to append observations is generating a 0-observations data-set for the base and appending that.
Correcting a modify-update dataset is also possible.
Data cor_updates ;
set base_obs ;
set old_updates ;
data cor_updates ;
attrib var1 ...... ; /*(correction var-defs) */
09-27-2014 01:30 AM
let's say you have data sets a (length of date_old=8) and b (length of date_old=4),
data new (drop=date_old rename=(date_new=date_old));
length date_new 4.;
set new b;
Keep posted to let us know, if it worked..