Date: Mon, 1 Mar 2010 21:34:12 -0500
Reply-To: Nathaniel Wooding <nathaniel.wooding@DOM.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Nathaniel Wooding <nathaniel.wooding@DOM.COM>
Subject: Re: Txt files with numeric and character values in one column
In-Reply-To: <7b0d30c8-369a-4bf9-bfef-6ca91da16b45@e1g2000yqh.googlegroups.com>
Content-Type: text/plain; charset="us-ascii"
Yaw
It would be very simple if you had a single character since you could tell SAS that it represented a missing value.
A solution that I like is to preprocess the input line before I read the variables. _INFILE_ is a special SAS variable that represents the contents of the input buffer. Note the "trailing @" which tells SAS to hold the pointer at the end of the buffer. The Translate statement turns the characters NA into a period which, to SAS, is a missing value. Then, we go back to the start of the line and read it. You can use this trailing @ for lots of stuff like checking each line and then using one of several different input statements.
Nat Wooding
data ab;
infile cards;
input @;
_infile_ = translate( _infile_ , '.' , 'NA' );
input @1 id sex mx1 mx2 ;
cards;
01 1 NA NA
02 2 0.35 NA
03 1 NA 1.00
run;
-----Original Message-----
From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of Yaw
Sent: Monday, March 01, 2010 5:59 PM
To: SAS-L@LISTSERV.UGA.EDU
Subject: Txt files with numeric and character values in one column
Dear All:
I am reading this text file from R which has both numeric and
character values in one column.
I used the (??) by the input statement. It however worked for some
columns but not all of them.
What could be amiss here? Any ideas?
My text data is like this
ID sex Mx1 Mx2
01 1 NA NA
02 2 0.35 NA
03 1 NA 1.00
And here is how I was going about it.
data ab;
infile .....;
input( id sex mx1 mx2) (??);
run;
Thanks,
Yaw
CONFIDENTIALITY NOTICE: This electronic message contains
information which may be legally confidential and or privileged and
does not in any case represent a firm ENERGY COMMODITY bid or offer
relating thereto which binds the sender without an additional
express written confirmation to that effect. The information is
intended solely for the individual or entity named above and access
by anyone else is unauthorized. If you are not the intended
recipient, any disclosure, copying, distribution, or use of the
contents of this information is prohibited and may be unlawful. If
you have received this electronic transmission in error, please
reply immediately to the sender that you have received the message
in error, and delete it. Thank you.