Re: [R] Reading sas7bdat files directly

2010-03-02 Thread Chris Long
The dsread output is little-endian, as that's the native format for 
floats on the Wintel platform.  The byte order should stay the same if 
converting directly to a float, using a data structure like (C/C++):

union {
 char bytes[8];
 double value;
}

If reading the values with a SAS HEX informat, the bytes will need to be 
reversed.  It's obviously trivial for me to add an endian-ness option, 
I'll do that later

Chris.

On 02/03/2010 02:06, Roger DeAngelis(xlr82sas) wrote:
 Hi,

It looks like we may need to swap bytes(little endian to big endian). I
 will look into it tonight.

As a side note, SAS reserves 28 floats for missing values. It should be
 easy to convert these to NaN on input to R.

 You can test this in SAS by converting the 16 char floats to ieee8. in SAS
 and doing a put. The result will be A, B...Z, . and _.

 SAS code that produced the listing is below.

 Here are the floats that map to the 28 missing values in SAS

 A  FD00
 B  FC00
 C  FB00
 D  FA00
 E  F900
 F  F800
 G  F700
 H  F600
 I  F500
 J  F400
 K  F300
 L  F200
 M  F100
 N  F000
 O  EF00
 P  EE00
 Q  ED00
 R  EC00
 S  EB00
 T  EA00
 U  E900
 V  E800
 W  E700
 X  E600
 Y  E500
 Z  E400
 _  FF00
 .  FE00

 data mis;
 retain A .A B .B C .C D .D E .E F .F G .G H .H I .I J .J K .K L .L M .M
 N .N O .O P .P Q .Q R .R S .S T .T U .U V .V W .W X .X Y .Y Z .Z
_ ._ DOT .;
 array mis[28] A B C D E F G H I J K L M N O P Q R S T U V W X Y Z _ DOT;
do idx=1 to 28;
   hex=put(mis[idx],ieee8.);
   xeh=put(hex,hex16.);
   put @1 mis[idx] @6 xeh;
end;




[[alternative HTML version deleted]]

__
R-help@r-project.org 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.


Re: [R] Reading sas7bdat files directly

2010-03-01 Thread Chris Long

dsread (http://www.oview.co.uk/dsread) was updated yesterday, to include
various new features as suggested here and elsewhere.  Of particular
interest might be:

- you can now use the /c and /v options together to get dataset contents in
CSV format for easier importing;

- there is now a /l option for lossless representation of numerics in the
output.  Numerics will appear as (eg) '0xf03f' giving the exact
hex value of each of the eight bytes making up the IEEE float value.

Please continue to report bugs or feature requests here or on the above web
page.

Thanks,

Chris.
-- 
View this message in context: 
http://n4.nabble.com/Reading-sas7bdat-files-directly-tp1469515p1574340.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org 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.


Re: [R] Reading sas7bdat files directly

2010-02-24 Thread Chris Long

I suppose a link would have added usefulness:

http://www.oview.co.uk/dsread

Chris.
-- 
View this message in context: 
http://n4.nabble.com/Reading-sas7bdat-files-directly-tp1469515p1567256.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org 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.


Re: [R] Reading sas7bdat files directly

2010-02-24 Thread Chris Long

No problem, Frank, I'm glad that you think it will be useful.

I will be making changes to dsread in the coming weeks so you may want to
hold off with your helper function in case my changes break it (the
formatting of the variable metadata listing may well change).  Re: the
metadata, feel free to suggest an alternate output format that would make
this a cleaner process.  For example, I have in mind to allow the -c
(contents) and -v (CSV) flags together, in which case the dataset metadata
will be output in CSV format.

Any other suggestions or comments are welcomed.

Chris.
-- 
View this message in context: 
http://n4.nabble.com/Reading-sas7bdat-files-directly-tp1469515p1567504.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org 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] Replacing NA values when building matrix using tapply

2007-10-05 Thread Chris Long
Hi,

I'm building a matrix m from a data frame d which includes the matrix row,
column and value.

This works well enough:

m - tapply(d[,value],d[,c(row,column)],c)

However, I'd like to replace any missing values with 0, not NA.  The
obvious doesn't work, however:

m - tapply(d[,value],d[,c(row,column)],function(x) 
{ifelse(is.na(x),0.0,x)})

I can always do this:

m - tapply(d[,value],d[,c(row,column)],c)
m[is.na(m)] - 0.0

But it's wasteful to process the table again.  Any ideas?
-- 
Christopher D. Long, San Diego Padres, 100 Park Boulevard, San Diego CA

Score: 0, Diff: 1, clong killed by a Harvard Math Team on  1

__
R-help@r-project.org 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.