DATA Step, Macro, Functions and more

Copy dataset structure

Accepted Solution Solved
Reply
Contributor
Posts: 58
Accepted Solution

Copy dataset structure

Hi all,

do there is a single way to copy only dataset structure?

I mean, I have a dataset with C columns and R rows, a would have a second dataset with the same C columns but with 0 rows.

Many thanks.

Regards


Accepted Solutions
Solution
‎10-22-2012 10:15 AM
Respected Advisor
Posts: 3,156

Re: Copy dataset structure

Then copy 0 rows over:

   data want;

   set   have (obs=0);

  run;
or

data want;

  set have;

stop;

run;

Haikuo

View solution in original post


All Replies
Solution
‎10-22-2012 10:15 AM
Respected Advisor
Posts: 3,156

Re: Copy dataset structure

Then copy 0 rows over:

   data want;

   set   have (obs=0);

  run;
or

data want;

  set have;

stop;

run;

Haikuo

Contributor
Posts: 58

Re: Copy dataset structure


Hi Haikuo,

Both works correctly, the first one is a littel bit faster.

Many thanks for your reply.

Antonio

Respected Advisor
Posts: 3,156

Re: Copy dataset structure

Antonio,

As a side note, if you are planning doing the same on datasets other than SAS tables, such as Oracle, sybase, SQL server etc, you may need to use the following standard SQL syntax:

CREATE TABLE want AS SELECT * FROM have  WHERE 1=0

and wrap it up using SAS pass-through. where condition can be anything not TRUE.

Please note: proc sql options such as inobs=, outobs= may not work in this kind of situation.

Haikuo

Respected Advisor
Posts: 4,924

Re: Copy dataset structure

I don't know how standard it is, but SAS SQL offers the command :

CREATE TABLE want LIKE have;

to create an empty table with the same structure as another table.

PG

PG
🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 3087 views
  • 0 likes
  • 3 in conversation