Freq1Var
From sasCommunity
%FREQ1VAR: Frequency of One Variable with Format: a Macro to standardize Proc Freq Output Data sets
http://www2.sas.com/proceedings/sugi24/Posters/p234-24.pdf
[edit] Proc Format
Create the formats in a separate program and store them in a permanent library.
*PROC Format library = Library fmtlib;
PROC Format library = Work fmtlib;
value $Gender 'F' = 'female'
'M' = 'male';
If you do not use libref Library then you need the fmtsearch option to set the search path.
[edit] Proc Freq
Here is the basic code that is in the paper.
%Let Libname = sashelp;
%Let Memname = class;
%Let Name = Sex;
%Let Format = $Gender.;
%Let XlsPath = C:\temp\xls;
%Let OutData = &Name.;
PROC Freq data = &Libname..&Memname;
tables &Name.
/ list missing noprint
out = Work.Freq;
*todo: if fileexist then delete;
libname XlsFile "&XlsPath.\&OutData..xls";
DATA XlsFile.&OutData.;
attrib Label length = $40;
drop &Name.;
do until(EndoFile);
set Work.Freq end = EndoFile;
Label = put(&Name.,&Format.);
*RJF2 2008-Oct-24 from SAS-L;
*Label = vvalue(&Name.);
output;
end;
stop;
run;
Proc Print data = &SysLast.;
run;
libname XlsFile clear;
run;
Thanks to C Chung for the libname to *.xls.
Note: the libname to *.xls will not overwrite an existing .xls file with the same name. Consider an x command to preemptively delete the file before the libname statement.
- 2008-Oct-28 SAS-L question about functions:
- Subject: Call Funtions explanations please
- call vname
- call label
- vvalue
--macro maven == the radical programmer 11:37, 5 August 2008 (EDT)
Or more concisely using ODS OUTPUT OneWayFreqs, as in this example.
PROC Format;
value $sex 'F'='Female'
'M'='Male';
value wt low - 75 = 'Low'
75 <- high = 'High';
value ht low - 60 = 'Low'
60 <- high = 'High';
run;
ods listing close;
PROC Freq data = sashelp.class(drop=name);
format sex $sex.
height ht.
weight wt.;
ods output OneWayFreqs = OneWayFreqs;
run;
ods listing;
DATA Work.OneWayFreqs;
length Label $256 Name $32. Type $1.;
keep Label Name Type Frequency Percent CumFrequency CumPercent;
set Work.OneWayFreqs;
label = coalesceC(of f_:);
name = scan(table,2,' ');
type = vtypex(name);
run;
- This page was last modified 17:02:06, 2008-10-27.
- This page has been accessed 339 times as of 2008-Nov-18.
- This page was last modified 16:03:38, 2008-11-18.
- This page has been accessed 1,593 times as of 2009-Jan-05.
