LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (July 2006, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Tue, 18 Jul 2006 22:56:14 +0000
Reply-To:   toby dunn <tobydunn@HOTMAIL.COM>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   toby dunn <tobydunn@HOTMAIL.COM>
Subject:   Re: Create Table Showing Number of Observations in Each Dataset
Comments:   To: walker.627@OSU.EDU
In-Reply-To:   <200607182250.k6IM7PBb025355@mailgw.cc.uga.edu>
Content-Type:   text/plain; format=flowed

Paul ,

O there are so many ways to get this, but lets assum you want all of the data sets in your work library and you want to use SQL:

Data D1 ; Do I = 1 To 250 ; Output ; End ; Run ;

Data D2 ; Do I = 1 To 450 ; Output ; End ; Run ;

Data D3 ; Do I = 1 To 850 ; Output ; End ; Run ;

Proc SQL ; Select MEMNAME Label = 'DataSet' , NOBS Label = 'NOBS' From Dictionary.Tables Where Libname = 'WORK' ; Quit ;

Toby Dunn

From: Paul Walker <walker.627@OSU.EDU> Reply-To: Paul Walker <walker.627@OSU.EDU> To: SAS-L@LISTSERV.UGA.EDU Subject: Create Table Showing Number of Observations in Each Dataset Date: Tue, 18 Jul 2006 18:50:42 -0400

I would like to create a table that looks like the following:

dataset nobs ------- --------- D1 10000 D2 12000 D3 7500

The column 'dataset' represents the name of a dataset, and nobs is the number of observations. Suppose there are 3 datasets as indicated, D1, D2, and D3. There are several ways to create such a table using macro variables or dictionary tables. However, I would like to use SQL to build this table in the following sort of way.

proc sql noprint; create table work.nobs_in_datasets as union a (count(*) as nobs, 'D1' as dataset from work.D1) b (count(*) as nobs, 'D2' as dataset from work.D2) c (count(*) as nobs, 'D3' as dataset from work.D3); quit;

However, I know the above code does not work and wondered if any PROC SQL experts could help correct my syntax? The basic problem is how to 'stack' the rows of data created by the code:

count(*) as nobs, 'D1' as dataset from work.D1; count(*) as nobs, 'D2' as dataset from work.D2; count(*) as nobs, 'D3' as dataset from work.D3;

TIA, -PW


Back to: Top of message | Previous page | Main SAS-L page