Date: Wed, 21 Jul 1999 21:00:10 -0400
Reply-To: S David Riba <dave@JADETEK.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: S David Riba <dave@JADETEK.COM>
Subject: Re: macro: data dict. to data set structure was: char2num ...
Content-Type: text/plain; charset="iso-8859-1"
If I understand what you are looking for, the following code snippet should
be fairly close. Sorry, Macro Maven, it's not a Macro -- just good ol' SAS
code. However, it might be useful to what you're trying to accomplish.
It is basically a three step process.
First, use PROC CONTENTS to create a SAS dataset with the descriptive
information needed (ie akin to the Data Dictionary that you are looking
for).
There is an intermediate manual step, where the observation values are
adjusted if necessary.
Finally, CALL EXECUTE is used to read the SAS dataset and write the code to
define a new SAS dataset with the revised structure and reload the data.
I will leave the actual purpose of this routine to your imagination until
you get to the bottom of the message <G>
/* Read SAS dataset and create CONTENTS output */
proc contents data=oldsurv noprint out=surveyx ;
run;
/* Sort by Alphabetic Variable Number */
proc sort data=surveyx ;
by varnum ;
run ;
/* At this point manually change values */
/* Use dataset as input to create new dataset */
data _null_ ;
if (_N_ eq 1) then do ;
call execute('data survey; length ') ;
do i = 1 to tobs ;
set surveyx point=i nobs=tobs ;
call execute(name) ;
if (type eq 2) then
call execute(' $ ') ;
else
call execute(' ') ;
call execute(length) ;
end ;
call execute('; label ') ;
do i = 1 to tobs ;
set surveyx point=i ;
if (length(trim(label)) gt 1) then do ;
call execute(name) ;
call execute(' = ') ;
call execute(label) ;
end ;
end ;
call execute(' ; ') ;
end ;
call execute ('set oldsurv ; ' ) ;
call execute ('run; ') ;
stop ;
run ;
That's it. OK. Any ideas what the above code does?
It re-alphabetizes and re-creates a SAS dataset with new variable values.
HTH
Dave
----------------------------------------------------------------------------
S. David Riba INTERNET: dave@JADETEK.COM
JADE Tech, Inc. http://www.jadetek.com
P O Box 4517
Clearwater, FL 33758
VOICE: (727) 726-6099 A SAS Institute Quality Partner
SAS. It's not just an attitude
-----Original Message-----
From: Fehd, Ronald J. <rjf2@CDC.GOV>
Newsgroups: bit.listserv.sas-l
To: SAS-L@LISTSERV.UGA.EDU <SAS-L@LISTSERV.UGA.EDU>
Date: Wednesday, July 21, 1999 5:47 PM
Subject: Re: macro: data dict. to data set structure was: char2num ...
>From: Karsten M. Self [mailto:kmself@IX.NETCOM.COM]
>> Subject: Re: char2num ... benefits o/formats
>
>> While we're at it, let's take a look at the proc FORMAT cntlin data set
>> model
>> and have something similar to read in the text of a data dictionary
>> into a data set and output a data set structure.
>> Features of such a proc might be:
>> calculating number of bytes needed based on precision specified for both
>> integer and real numbers
>>
>> ... damn, this would be a might fine macro, if ever I saw one. LOL
>> and I definitely need such a sucker. ... er, proc.
>
>/Could you clarify this thought?
>
>/I have written an input statement generator from SQL DESCRIBE TABLE
>/output. It got the job done, though it was something of a bear.
>
>I would like to take -- i.e. cut&paste -- a data set description out of a
>data dictionary document and read it into a data set similar to what we get
>out of proc CONTENTS,
>do some calculations, as hinted at above, then write a data set structure,
>or, more appropriately for SAS, write either
>proc DATASETS statements to associate formats with variables
>or an attrib statement that will fix length, label _and_ format.
>
>right now I'm wringing my hands because I'm testing a new utility and
>finding that my data sets have formats that are not in the format library.
>Kludge I can do. I'd rather have a method, tho, and this would be it.
>
>Ron Fehd the macro designer CDC Atlanta GA