BookmarkSubscribeRSS Feed
Eva
Quartz | Level 8 Eva
Quartz | Level 8

Dear all,

I's like to create a new data set that has exactely the same fields as an existing data set. And the fields should all have the same definitions, i.e. char/num and their lengths. How can I do this? Is it possible to "copy" a dataset without its data rows?

(After I have this empty new dataset I'd like to insert just one row with the values I assign.)

Best wishes,

Eva

3 REPLIES 3
Eva
Quartz | Level 8 Eva
Quartz | Level 8

I found a solution in the manaul for prc sql and the create table statement:

proc sql;

     /* create same table but empty */

     create table work.calss like sashelp.class;

     /* insert new row */

     insert into work.class

     set

     name='Eva',

     sex='F',

     age='99',

     height=123,

     weight=888;

quit;

LinusH
Tourmaline | Level 20

Like works nice, but it does not copy any index information to the target table.

If you want that, you can use PROC APPEND with a non existing BASE table.

This will result that the BASE table will be created, using the metadata from the DATA table.

Proc Append Base=Want Data=Have(obs=0);

Run;

/Linus

Data never sleeps
Haikuo
Onyx | Level 15

If using Datastep, you could also try:

data have;

name='Eva1';

     sex='F1';

     age='991';

     height=1231;

     weight=8881;

run;

data want;

if 0 then set have;

name='Eva';

      sex='F';

      age='99';

      height=123;

      weight=888;

      run;

Regards,

Haikuo

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 3 replies
  • 765 views
  • 1 like
  • 3 in conversation