[R] R and SAS proc format

Carlos J. Gil Bellosta cgb at datanalytics.com
Wed Mar 7 16:07:16 CET 2007


On 3/7/07, Peter Dalgaard <P.Dalgaard at biostat.ku.dk> wrote:
> Jason Barnhart wrote:
> > ----- Original Message -----
> > From: "John Kane" <jrkrideau at yahoo.ca>
> > To: "lamack lamack" <lamac_k at hotmail.com>; <R-help at stat.math.ethz.ch>
> > Sent: Tuesday, March 06, 2007 2:13 PM
> > Subject: Re: [R] R and SAS proc format
> >
> >
> >
> >> --- lamack lamack <lamac_k at hotmail.com> wrote:
> >>
> >>
> >>> Dear all, Is there an R equivalent to SAS's proc
> >>> format?
> >>>
> >> What does the SAS PROC FORMAT do?
> >>
> >
> > It formats or reformats data in the SAS system.
> >
>
> Slightly more precisely: It creates user-defined formats, which are
> subsequently associated with variables and used for reading, printing,
> tabulating, and analyzing data. It is akin to R's factor()
> constructions, but not quite. For one thing, SAS's formats are separate
> entities - same format can be used for many variables, whereas R's
> factors have the formatting coded as a part of the object. For related
> reasons, a variable in SAS can have more distinct values than there are
> value labesl for, etc.
> > It looks this:
> >
> >     proc format; value kanefmt 1='A' 2='B' 3='C' 4='X' 5='Throw me
> > out';
> >     data temp; do i=1 to 10; kanevar=put(i,kanefmt.); output; end;
> >     proc print; run;
> >
> > And produces this:
> >
> > Obs     i      kanevar
> >   1     1    A
> >   2     2    B
> >   3     3    C
> >   4     4    X
> >   5     5    Throw me out
> >   6     6               6
> >   7     7               7
> >   8     8               8
> >   9     9               9
> >  10    10              10
> >
> >
> > But it is more robust than what is shown here.
> >
> >
> >
> >
> >> ______________________________________________
> >> R-help at stat.math.ethz.ch mailing list
> >> https://stat.ethz.ch/mailman/listinfo/r-help
> >> PLEASE do read the posting guide
> >> http://www.R-project.org/posting-guide.html
> >> and provide commented, minimal, self-contained, reproducible code.
> >>
> >>
> >
> > ______________________________________________
> > R-help at stat.math.ethz.ch mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> >
>
>
> --
>    O__  ---- Peter Dalgaard             Øster Farimagsgade 5, Entr.B
>   c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
>  (*) \(*) -- University of Copenhagen   Denmark          Ph:  (+45) 35327918
> ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)                  FAX: (+45) 35327907
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

Also, SAS formats are used as a (somewhat cumbersome) replacement for
"dictionary" data structures. Starting from SAS 9.1 (I believe), "hash
tables" can be used within data steps for the same purpose (albeit
still cumbersome).

In this regard, not only formats but also lists could be a replacement
for them. They can be used as a way to get key-value mappings.

These key-value mappings (I mean, these kind of data structures) are
very handy tools. I have used both factors and lists for some kind of
"ad hoc" replacement for these data structures. Hasn't anybody
considered the posibility of having these data structures implemented
in R in a much python-like or java-like touch and feel?

Regards,

Carlos J. Gil Bellosta
http://www.datanalytics.com



More information about the R-help mailing list