Programming the statistical procedures from SAS

create a zero observation dataset

Accepted Solution Solved
Reply
N/A
Posts: 0
Accepted Solution

create a zero observation dataset

how can create a zero observation dataset?

Accepted Solutions
Solution
a month ago
Respected Advisor
Posts: 3,773

Re: create a zero observation dataset

[ Edited ]

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


All Replies
Solution
a month ago
Respected Advisor
Posts: 3,773

Re: create a zero observation dataset

[ Edited ]

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;
N/A
Posts: 0

Re: create a zero observation dataset

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
N/A
Posts: 0

Re: create a zero observation dataset

could you tell me use of stop statement
Respected Advisor
Posts: 3,773

Re: create a zero observation dataset

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.
SAS Super FREQ
Posts: 8,690

Re: create a zero observation dataset

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
New Contributor
Posts: 4

Re: create a zero observation dataset

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;

☑ This topic is SOLVED.

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

Discussion stats
  • 6 replies
  • 8002 views
  • 0 likes
  • 4 in conversation