| Date: | Mon, 13 Dec 2004 08:46:03 -0500 |
| Reply-To: | "Michael S. Zdeb" <msz03@HEALTH.STATE.NY.US> |
| Sender: | "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU> |
| From: | "Michael S. Zdeb" <msz03@HEALTH.STATE.NY.US> |
| Subject: | Re: Simulating PRELOADFMT in PROC FREQ |
|
| Content-type: | text/plain; charset=US-ASCII |
|---|
Hi. You could try using PROC SUMMARY with no VAR statement instead of
FREQ. It support PRELOADFMT. The CLASS statement replaces the TABLE
statement...
* a test format ;
proc format;
value yesno
1='Yes'
0='No'
;
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;
proc summary data=one nway completetypes;
class x y;
output out=_one (drop=_type_ rename=(_freq_=count1));
format x yesno.;
run;
proc summary data=two nway completetypes;
class x y;
output out=_two (drop=_type_ rename=(_freq_=count2));
format x yesno.;
run;
data one_two;
merge _one _two;
by x y;
run;
proc print data=one_two;
run;
Obs x y count1 count2
1 No 4 1 0
2 No 5 1 0
3 Yes 4 1 1
4 Yes 5 1 1
Mike Zdeb
U@Albany School of Public Health
1 University Drive
Rensselaer, NY 12144-3456
(P)518-402-6479
(F)630-604-1475
|---------+-------------------------------------------->
| | Scott |
| | <usenet739_yahoo_com_au@CRONKITE.|
| | CC.UGA.EDU> |
| | Sent by: "SAS(r) Discussion" |
| | <SAS-L@LISTSERV.UGA.EDU> |
| | |
| | |
| | 12/12/2004 08:47 PM |
| | Please respond to Scott |
| | |
|---------+-------------------------------------------->
>----------------------------------------------------------------------------------------------------------------------|
| |
| To: SAS-L@LISTSERV.UGA.EDU |
| cc: |
| Subject: Simulating PRELOADFMT in PROC FREQ |
>----------------------------------------------------------------------------------------------------------------------|
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;
|