BookmarkSubscribeRSS Feed
durga
Calcite | Level 5

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.

5 REPLIES 5
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

Ksharp
Super User

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

Tom
Super User Tom
Super User

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.

jakarman
Barite | Level 11

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 --<-----
nravi
Calcite | Level 5

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..

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 5 replies
  • 1883 views
  • 0 likes
  • 6 in conversation