Date: Fri, 29 Sep 2000 21:16:31 GMT
Reply-To: sashole@mediaone.net
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Paul Dorfman <paul_dorfman@HOTMAIL.COM>
Subject: Re: Proc Means Result into SAS dataset
Content-Type: text/plain; format=flowed
Ian,
Interesting code and story. Let me only add that even though the pre-ODS,
days-of-yore way of doing things like this by redirecting printed output to
a temporary file and parsing the latter is nowadays is seen largely as a
kludge, its path to the goal is pretty short, and it does not appear to have
too much unwanted specificity. Outside of the mainframe, recfm=fb should be
omitted.
option nocenter ls=256;
filename prn '&prn' recfm=fb;
proc printto print=prn;
proc means data=w n nmiss min max var skew; var x y z;
proc printto print=print;
data out;
infile prn;
do until (_infile_ =: '-'); input; end;
do until (0);
input;
length variable $ 32 label $ 256;
variable = scan(_infile_,1,'');
label = scan(_infile_,2,'');
if input(label, ?? 1.) ne . then label = '';
array stat n nmiss minimum maximum variance skewness;
do over stat;
stat = input(scan(_infile_,_i_+2-(label=''),''),best.);
end;
if _infile_ =: '-' then stop;
output;
end;
run;
Of course, the _infile_ usage is specific to V>6.
Kind regards,
=======================
Paul M. Dorfman
Jacksonville, Fl
=======================
>From: Ian Whitlock <WHITLOI1@WESTAT.COM>
>Reply-To: Ian Whitlock <WHITLOI1@WESTAT.COM>
>To: SAS-L@LISTSERV.UGA.EDU
>Subject: Re: Proc Means Result into SAS dataset
>Date: Fri, 29 Sep 2000 12:15:34 -0400
>
>Subject: Proc Means Result into SAS dataset
>Summary: V8 Makes it easier, but not too easy.
>Respondent: Ian Whitlock <whitloi1@westat.com>
>
>K.Shide [mailto:shide@POP16.ODN.NE.JP] asked how to use PROC
>MEANS to make an output SAS data set similar to the report.
>
>Paige Miller [mailto:paige.miller@KODAK.COM] made the nice
>suggestion that perhaps an ODS OUTPUT statement could be used.
>
> ods output means.summary = look ;
> proc means data = w ;
> var x y z ;
> output out = summry ( drop = _freq_ _type_ )
> N= Nmiss= Min= Max= Var= skew=
> / autoname ;
> run ;
> ods output close ;
>
>The above code just produces a one record set similar to OUTPUT
>statement. There may still be an ODS solution, but it is not obvious
>to me.
>
>At one time, I had a trick for getting the old MEANS style output.
>Unfortunately I cannot remember exactly what it was and I suspect
>that the ability to create this kind of output went away sometime
>late in version 6. Can anyone confirm that?
>
>Well what's left? Data manipulation. Here is a program to
>illustrate. I didn't package it as a macro, because the key changes
>all occur in the PROC MEANS step (except for the final output dsn).
>
> /* make test data */
> data w ;
> do obs = 1 to 20 ;
> x = rannor ( 67695 ) ;
> y = ranuni ( 0 ) ;
> z = 1000 * ranuni ( 0 ) ;
> output ;
> end ;
> label x = "XXXX" z = "ZZZZ" ;
> run ;
>
>
>
>
> /* assumptions
> names do not contain "_"
> names short enough to add stat
> modify following step - remainder is stable
> */
> proc means data = w noprint ;
> var x y z ;
> output out = summry ( drop = _freq_ _type_ )
> N= Nmiss= Min= Max= Var= skew=
> / autoname ;
> run ;
>
> proc transpose data = summry out = t1 ;
> var _all_ ;
> run ;
>
> data t1 ( drop = _name_ ) ;
> length variable $ 32 ;
> set t1 ;
> variable = scan ( _name_ , 1 , "_" ) ;
> stat = scan ( _name_ , 2 , "_" ) ;
> run ;
>
> proc sort data = t1 ;
> by variable ;
> run ;
>
> proc transpose data = t1 out = t2 ( drop = _name_ ) ;
> by variable ;
> id stat ;
> var col1 ;
> run ;
>
> proc sql ;
> create table labs as
> select distinct variable , _label_
> from t1
> order by variable
> ;
> quit ;
>
> data q ;
> merge t2 labs ;
> by variable ;
> if _label_ = " " then _label_ = variable ;
> run ;
>
>I wrote this in part thinking about a macro that Mike Rhoads
>presented in a SUGI just after PROC SUMMARY came out (1983-1985). It
>presented an answer to this question and more. When I first saw it,
>I told my wife to go get a job at Westat on the basis of that paper.
>(It took me several years to learn the wisdom of following that
>advice.)
>
>The AUTONAME feature in V8 and SQL make the task much easier
>than it used to be, but one still has to wonder why PROC MEANS had to
>lose a feature that it once had, and why the table structure for the
>output report was not preserved in the ODS output object.
>
>Ian Whitlock
_________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.
Share information about yourself, create your own public profile at
http://profiles.msn.com.
|