DATA Step, Macro, Functions and more

date field length need to change from 8 byte to 4 byte.

Reply
Occasional Contributor
Posts: 8

date field length need to change from 8 byte to 4 byte.

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.

Thank You,

Durga.

Super User
Super User
Posts: 7,997

Re: date field length need to change from 8 byte to 4 byte.

Hi,

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.

Super User
Posts: 10,046

Re: date field length need to change from 8 byte to 4 byte.

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 ?

proc sql;

create table want as

select * from one

union all corr

select * from two ;

quit;

If you have to convert 8 into 4 ,then you have to make another variable which has length of 4 .

length new 4 ;

new=old;

But that might be losing exact float .

Xia Keshan

Super User
Super User
Posts: 7,081

Re: date field length need to change from 8 byte to 4 byte.

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.

Trusted Advisor
Posts: 3,215

Re: date field length need to change from 8 byte to 4 byte.

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 ;

run;

or

data cor_updates ;

attrib var1   ...... ;  /*(correction var-defs) */

set old_updates;

run;

---->-- ja karman --<-----
Occasional Contributor
Posts: 5

Re: date field length need to change from 8 byte to 4 byte.

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 a;

date_new=date_old;

run;

data all;

set new b;

run;

Keep posted to let us know, if it worked..

Ask a Question
Discussion stats
  • 5 replies
  • 268 views
  • 0 likes
  • 6 in conversation