BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
how can create a zero observation dataset?
1 ACCEPTED SOLUTION

Accepted Solutions
data_null__
Jade | Level 19

By stopping before you output and if you want before you read any obs.  Use the STOP statement.

 

data likeshoes;
 stop;
 set sashelp.shoes;
run;

 

Log:

 

NOTE: The data set WORK.LIKESHOES has 0 observations and 7 variables.


Other methods - use OBS=0 on the SET statement, or PROC SQL with the LIKE statement.

 

data likeshoes;
 set sashelp.shoes (obs=0);
run;

proc sql;
  create table test like sashelp.shoes;
quit;

View solution in original post

7 REPLIES 7
data_null__
Jade | Level 19

By stopping before you output and if you want before you read any obs.  Use the STOP statement.

 

data likeshoes;
 stop;
 set sashelp.shoes;
run;

 

Log:

 

NOTE: The data set WORK.LIKESHOES has 0 observations and 7 variables.


Other methods - use OBS=0 on the SET statement, or PROC SQL with the LIKE statement.

 

data likeshoes;
 set sashelp.shoes (obs=0);
run;

proc sql;
  create table test like sashelp.shoes;
quit;
deleted_user
Not applicable
Hi Leena,

You can also use two methods to do this:

data likeshoes;
set sasuser.shoes (obs=0);
run;


OR
proc sql;
create table test like sasuser.shoes;
quit;


Thanks,
Saurabh
deleted_user
Not applicable
could you tell me use of stop statement
data_null__
Jade | Level 19
In a data step when no user supplied OUTPUT statement is coded there is an implied output statement and a RETURN statement. So unless changed all SAS data steps end with OUTPUT; RETURN;

The zero obs data set data step could be thought of as being coded like this.

[pre]
data zero;
stop;
set sashelp.class;
OUTPUT;
RETURN;
run;
[/pre]

The STOP is needed to keep that implied OUTPUT from executing, without it you would get a data set with 1 observation.
Cynthia_sas
SAS Super FREQ
Hi:
The SAS documentation is an invaluable resource to answer questions like these. For example, the STOP statement documentation:
http://support.sas.com/documentation/cdl/en/lrdict/62618/HTML/default/a000214597.htm

And other processing statements relevant to the DATA step are outlined here with links to the specific documentation topic (I have this link bookmarked and recommend that my students make this link a favorite):
http://support.sas.com/documentation/cdl/en/lrdict/62618/HTML/default/a001225397.htm

But, support.sas.com can be used for more than just documentation lookups. For example, a question about creating a zero observation dataset can be researched on support.sas.com. For example, if you go to support.sas.com and enter the search string:
create zero obs dataset


in the search box in the upper right hand corner of the support web page, then the first hit returned from the search is this user group paper, entitled:

SUGI 28: Creating Tables or Listings with a Zero-Record SAS(r) Data Set -- Basic Program Structure and Three Simple Techniques

with a link directly to the paper:
http://www2.sas.com/proceedings/sugi28/218-28.pdf

AND, the paper discusses the reasons why you might want to create a zero obs dataset.

SUPPORT.SAS.COM contains a wealth of knowledge -- not just documentation. When you search, you can restrict yourself to the SAS Notes, to the SAS Documentation or you can search all available resources and samples. Learning to navigate these resources and use them, will help you in all your programming endeavors.

cynthia
Suman999
Calcite | Level 5

Datastep:

 

Method1:

 

data data2;
set sashelp.class(obs=0);
run;
proc print data=data2;

run;

 

Method2:

 

data data3;
stop;
set sashelp.class;
run;

 

SQL :

 

proc sql;
create table data4 like sashelp.class;
quit;

arpi
Fluorite | Level 6

To create a zero observation dataset with column specifications:

 

DATA work.MEMBER;
LENGTH NAME $ 28 DOB 4;
FORMAT DOB DATE9.;
INFORMAT DOB DATE9.;
STOP;
RUN;

It is same like Create Table doing PROC SQL.

 

proc sql;
create table work.member
(Name varchar(28) ,
DOB num format date9.
);

quit;

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!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 7 replies
  • 40997 views
  • 5 likes
  • 5 in conversation