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

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 1475 views
  • 0 likes
  • 6 in conversation