Date: Mon, 11 Sep 2006 15:35:29 +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: Help Needed in Proc Freq
In-Reply-To: <E7512ADD0779B74592AF6E0E740347160123DC64@exp-kogr1.cdc.gov>
Content-Type: text/plain; format=flowed
Praveen ,
Ron is being modest here, he really did strike upon something extremely good
here. In fact after reviewing his paper I adapted his work to fill a hole I
needed in my work. I have since adjusted this to work in the set of
programs that I use today. Here is the code that I use and I encourage you
to go back and read Rons paper first. The concept he came up with was
brilliantly simple yet very effective. NOw if only I can start having thos
simple yet profound thoughts....
%macro FreqAll( Lib = Work , Mem = , Vars = , NObs2View = , Format = YES ,
Order = INTERNAL ) ;
/*****************************************************************************/
/** Macro Name : FreqAll
**/
/**
**/
/**
**/
/** Purpose : The FreqAll macro creates a customized frequency listing
**/
/** of specified vars.
**/
/**
**/
/**
**/
/** Parameters : LibIn ~ Libname of the Data Set containing the data to run
**/
/** the frequencies on. Default value is 'WORK'.
**/
/**
**/
/** MemIn ~ Name of the Input Data Set. No Defualt Value.
**/
/**
**/
/** Vars ~ Listing of variables to perform the frequency
**/
/** on.
**/
/** Valid values are: _All_ - All Vars
**/
/** _Numeric_ - Numeric Vars Only
**/
/** _Character_ - Character Vars
Only**/
/** User Supplied List of Var Names
**/
/**
**/
/** NObs2View ~ A number representing the Top N frequency
**/
/** to be included in the report. If no value is
**/
/** specified then all of the frequency values
will**/
/** be included in the report. No default value.
**/
/**
**/
/** Format ~ Specifies whether to print the frequency
**/
/** values by their associated formats.
**/
/** Valid Values are 'Yes' and 'No'. The Default
**/
/** Value is 'YES'.
**/
/**
**/
/** Order ~ Specifies how SAS should group the data in the
**/
/** frequency analysis.
**/
/** Valid Values: Internal, Data, Formatted, Freq
**/
/** Default value is Internal.
**/
/*****************************************************************************/
%Local DataToUse ;
%If ( %Upcase( &Format ) = NO ) %Then %Do ;
data MyData ;
set &Lib..&Mem ;
format _all_ ;
informat _all_ ;
run ;
%Let DataToUse = MyData ;
%End ;
%Else %do ;
%Let DataToUse = &Lib..&Mem ;
%End ;
ods listing close ;
ods output onewayfreqs = Freqs ;
Proc freq
Data = &DataToUse Order = &Order ;
Table &Vars / Missing ;
Run ;
Ods Listing ;
Data NewFreqsA ( Keep = Var Val Frequency Percent Level ) ;
Set Freqs ( Drop = Cum: F_: ) ;
By Table NotSorted ;
If First.Table then Level = 0 ;
Level + 1 ;
Var = Compress( Scan( Table , 2 , ' ' ) ) ;
Val = Left( Strip( VValueX( Var ) ) ) ;
Run ;
Proc Sql ;
Create Table NewFreqsB As
Select A.* ,
Compbl( A.Var || ' ' || B.Attr ) as Attribute
From NewFreqsA as A
Left Join
(Select Name , Compbl( Type || ':' || Put( Length , 8. -L ) || Label
) as Attr
From Dictionary.columns
Where Libname = %Upcase( "&Lib" ) and Memname = %UpCase( "&MEM" ) )
as B
On A.Var = B.Name
%If ( %Length( &NObs2View ) > 0 ) %Then %Do ;
Group By A.Var
Having ( A.Level <= &NObs2View ) or
( A.Level >= ( Max( A.Level ) - &Nobs2View ))
%End ;
Order by A.Var , A.Level ;
Quit ;
Options NoDate NoNumber ;
Title1 "Program FreqAll: &Lib..&Mem" ;
Title2 "List of Variable Frequencies" ;
Proc print
Data = NewFreqsB NOOBS ;
Var Val Frequency Percent Level ;
by Attribute ;
id Attribute ;
Run ;
Proc DataSets ;
Delete NewFreqsA
NewFreqsB
%If ( %SysFunc( Exist( MyData ) ) ) %Then %Do ;
MyData
%End ;
;
Quit ;
Title1 ;
Title2 ;
Options Date Number ;
%Mend FreqAll ;
%FreqAll( Lib = sashelp , Mem = prdsal2 , Vars = _all_ , NObs2View = 10 )
Toby Dunn
When everything is coming at you all at once, your in the wrong lane.
A truly happy person is someone who can smile and enjoy the scenery on a
detour.
From: "Fehd, Ronald J. (CDC/CCHIS/NCPHI)" <rjf2@CDC.GOV>
Reply-To: "Fehd, Ronald J. (CDC/CCHIS/NCPHI)" <rjf2@CDC.GOV>
To: SAS-L@LISTSERV.UGA.EDU
Subject: Re: Help Needed in Proc Freq
Date: Mon, 11 Sep 2006 11:09:20 -0400
> From: pavan kumar
> I have a Code ::
>
> Proc freq data = customer NOPRINT;
> tables pdga1 pdgh sghal sdfg / out = out_freq;
> run;
>
> i am trying to know the counts and Percents of all
> the variables mentioned
>
> in Tables statement but the problem is i am getting
> the output for only
> last variables . How can i get for all the
> variables . Kindly Plz Help me out
I solved this problem in the last decade of the previous century
and finally posted the code last december:
check our most excellent archives:
http://www.listserv.uga.edu/archives/sas-l.html
search for:
substring search: [X]
subject contains: tip
author's address: RJF2
since: dec 2005
until:
Ron Fehd the macro maven CDC Atlanta GA USA RJF2 ata cdc d0t g0v
Date: Mon, 19 Dec 2005 11:55:49 -0500
Subject: tip: macro FreqAllVars