| Date: | Mon, 13 Dec 2004 08:43:58 -0500 |
| Reply-To: | Jonas Bilenas <Jonas.Bilenas@CHASE.COM> |
| Sender: | "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU> |
| From: | Jonas Bilenas <Jonas.Bilenas@CHASE.COM> |
| Subject: | Re: Simulating PRELOADFMT in PROC FREQ |
|---|
PROC FREQ will support the order=formatted option. To force YES first, try:
proc format;
value yesno 1 = ' YES'
0 = 'NO'
;
proc freq data=test order=formatted;
table yesno;
format yesno yesno.;
run;
On Mon, 13 Dec 2004 04:45:28 -0800, Dennis Diskin <diskin@SNET.NET> wrote:
>Scott,
>
>If you just need the equivalent output data set that freq would produce,
why go to all the trouble. Just use summary to produce the counts. If you
need the percents, it's just one more step. Here's an example:
>
>HTH,
>Dennis Diskin
>
>* a test format ;
>proc format;
> value yesno
> 1='Yes'
> 0='No'
> ;
>run;
>
>* test data, only one value for x ;
>data two;
>input x y;
>format x yesno.;
>cards;
>1 4
>1 5
>;
>run;
>
>/* if you don't need percents */
>proc summary completetypes data=two nway;
>class x / preloadfmt;
>class y;
>output out=b(drop=_type_ rename=_freq_=count);
>run;
>
>
>/* or to calculate overall percent for each cell */
>proc summary completetypes data=two;
>class x / preloadfmt;
>class y;
>output out=b(where=(_type_ in (0,3)));
>run;
>
>data c(drop=_type_ total rename=_freq_=count);
>set b;
>if _type_ eq 0 then do;
> total+_freq_;
> delete;
>end;
>percent = 100*_freq_ / total;
>run;
>
>
>Scott <usenet739_yahoo_com_au@CRONKITE.CC.UGA.EDU> wrote:
>SAS v8.2 under Windows
>
>Hi,
>
>I need to simulate the PRELOADFMT option in PROC FREQ. Below is a
>simplified example and my intended approach. Can you see any better
>approach? Note that the procedure must be FREQ (part of a larger utility
>macro).
>
>As an aside, it looks like the preloadfmt for proc freq has been on the
>SASWare ballot since 2000. Have you heard any rumors about when it might be
>implemented in SAS?
>
>Thanks,
>Scott
>
>TEST CODE:
>
>* a test format ;
>proc format;
>value yesno
>1='Yes'
>0='No'
>;
>run;
>
>* using cntlout, it would get very messy to do the merge at the end of this
>code ;
>proc format cntlout=fmtout;
>select yesno;
>run;
>
>* some test data ;
>data one;
>input x y;
>format x yesno.;
>cards;
>1 4
>1 5
>0 4
>0 5
>;
>run;
>
>* test data, only one value for x ;
>data two;
>input x y;
>format x yesno.;
>cards;
>1 4
>1 5
>;
>run;
>
>* tabulate supports the preloadfmt option - note the second example ;
>proc tabulate data=one;
>class x / order=internal preloadfmt;
>class y / order=internal preloadfmt;
>table all=n x,y / printmiss;
>run;
>proc tabulate data=two;
>class x / order=internal preloadfmt;
>class y / order=internal preloadfmt;
>table all=n x,y / printmiss;
>run;
>
>* freq does not support the preloadfmt option - note the second example ;
>proc freq data=one;
>tables x*y / sparse out=freq_one;
>run;
>proc freq data=two;
>tables x*y / sparse out=freq_two;
>run;
>
>* simulate preloadfmt in freq by executing both tabulate and freq,
>then merging the two. note this only works for output datasets -
>the output from freq would not have the missing data ;
>ods listing close;
>ods output Table=tab_one;
>proc tabulate data=one;
>class x / order=internal preloadfmt;
>class y / order=internal preloadfmt;
>table x,y / printmiss;
>run;
>ods output Table=tab_two;
>proc tabulate data=two;
>class x / order=internal preloadfmt;
>class y / order=internal preloadfmt;
>table x,y / printmiss;
>run;
>ods listing;
>
>* now simulate the preloadfmt in freq - note the second example ;
>data merge_one;
>merge freq_one tab_one (keep=x y);
>by x y;
>run;
>proc print;
>run;
>data merge_two;
>merge freq_two tab_two (keep=x y);
>by x y;
>run;
>proc print;
>run;
|