BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
garag
Calcite | Level 5

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

1 ACCEPTED SOLUTION

Accepted Solutions
Haikuo
Onyx | Level 15

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

4 REPLIES 4
Haikuo
Onyx | Level 15

Then copy 0 rows over:

   data want;

   set   have (obs=0);

  run;
or

data want;

  set have;

stop;

run;

Haikuo

garag
Calcite | Level 5


Hi Haikuo,

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

Many thanks for your reply.

Antonio

Haikuo
Onyx | Level 15

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

PGStats
Opal | Level 21

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

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