DATA Step, Macro, Functions and more

Option to read INFILE similar to CAPS option for CARDS or PARMCARDS

Reply
Respected Advisor
Posts: 3,799

Option to read INFILE similar to CAPS option for CARDS or PARMCARDS

I want to read a file and ignore case. I want all alpha characters converted to UPPERCASE or lowercase when SAS puts the record in the input buffer so I don't have to do it using something like

[pre]
INPUT @;
_infile_ = lowcase(_infile_);
input .........
[/pre]
Is this possible? Message was edited by: data _null_;
Super User
Posts: 10,041

Re: Option to read INFILE similar to CAPS option for CARDS or PARMCARDS

Posted in reply to data_null__
Hi, data _null_;
you try this.

[pre]
data temp;
input sex $upcase1.;
datalines;
F
m
m
M
f
f
F
;
[/pre]
Respected Advisor
Posts: 3,799

Re: Option to read INFILE similar to CAPS option for CARDS or PARMCARDS

I see I wasn't clear. I want to use @'string' in an INPUT statement and ignore case.
Super User
Posts: 10,041

Re: Option to read INFILE similar to CAPS option for CARDS or PARMCARDS

Posted in reply to data_null__
Sorry. not understand your mean.
Respected Advisor
Posts: 4,173

Re: Option to read INFILE similar to CAPS option for CARDS or PARMCARDS

Posted in reply to data_null__
Hi data _null_

I would say it's not possible because:
- The INFILE statement only defines where and how a record should be read into the input buffer.
- The null INPUT statement then causes SAS to read the record based on the definitions given by the infile statement. It's only reading - nothing gets altered. Only during the variable mapping against the input buffer data gets altered based on the informats.

And that's why I think the code you've given is the most efficient way possible to achieve what you want.

Well: Unless there is some undocumented system options or option for the INFILE statement I don't know of.

HTH
Patrick Message was edited by: Patrick
Respected Advisor
Posts: 3,799

Re: Option to read INFILE similar to CAPS option for CARDS or PARMCARDS

Hi Patrick,

Thanks, using lowcase/upcase on _INFILE_ works well enough, but I really wanted to use SCANOVER with an input statement that scans records looking for text but igonring case.

[pre]
input @'scan for string1' val1 @'scan for string2' val2 ...;
[/pre]

I have been experimenting with @(prxmatch('/target/i')) but this positions the input pointer at the start of the found string so I need to +(length(target)).
Valued Guide
Posts: 634

Re: Option to read INFILE similar to CAPS option for CARDS or PARMCARDS

Posted in reply to data_null__
I hope this is not a step backwards, but you mention the CAPS option. Does this not do what you want?

[pre]
options caps;
data a;
input @'A' aftera $;
datalines;
d s e r a qwert qawetrqq A222qwerrt
run;
proc print data=a;
run;
[/pre]
Respected Advisor
Posts: 3,799

Re: Option to read INFILE similar to CAPS option for CARDS or PARMCARDS

Yes but that only works for CARDS and PARMCARDS. I am reading PROC PRINTTO output. There is a z/OS option CAPSOUT that would produce the desired result but I'm using winders.
Super Contributor
Super Contributor
Posts: 3,174

Re: Option to read INFILE similar to CAPS option for CARDS or PARMCARDS

Posted in reply to data_null__
A Google advanced search using the argument "input informat uppercase site:sas.com" revealed this gem in the SAS 9.2 DOC, discussing the CAPS system option and also the $UPCASE INFORMAT.


SAS 9.2 Language Reference: Concepts, Reading Raw Data: Types of Data
http://support.sas.com/documentation/cdl/en/lrcon/62955/HTML/default/a003209899.htm

Scott Barry
SBBWorks, Inc.
Valued Guide
Posts: 634

Re: Option to read INFILE similar to CAPS option for CARDS or PARMCARDS

Since you cannot use DATALINES, you could still process against _INFILE_ after it has been brought into the PDV. The nested functions become a bit awkward but should not be too bad.

[pre]
* TRYCAP.TXT contains the data line from above.;
filename txtline "c:\temp\trycap.txt";
data a;
infile txtline ;
input ;
aftera = scan(substr(_infile_,index(upcase(_infile_),'A')+1),1);
put _infile_;
put aftera =;
run;
proc print data=a;
run;
[/pre]

This has the advantage of a case insensitive search, but the original case is preserved in the final data set.
Valued Guide
Posts: 2,177

Re: Option to read INFILE similar to CAPS option for CARDS or PARMCARDS

data _null_; seeks a linguistic search with input @'string'
A really nice idea, but not yet supported. (I say YET because introduced in SAS92 are "linguistic" extensions to proc sort and others.
Back in time SAS infile options included scope to define a user module (iirc it was a feature on the mvs platform - like everything once was mvs platform;-)
A link to a sample program from (using the infile/file user exit facility) http://support.sas.com/documentation/cdl/en/hosto390/61886/HTML/default/viewer.htm#/documentation/cd...
May provide a direction to support entirely uppercasing the infile buffer, while sharing the external file reference with an infile which does not uppercase everything.

Unfortunately, I see no documentation suggesting "INFILE/FILE User Exit Facility" is available on other platforms.

just a thought

peterC
Super User
Posts: 3,257

Re: Option to read INFILE similar to CAPS option for CARDS or PARMCARDS

There is an item in the latest SASware Ballot in the Language category on this issue:

"add an option on the INFILE statement that enables you to perform case-insensitve comparisons by including @'string' on the INPUT statement"

If you are keen you should vote for it!
Ask a Question
Discussion stats
  • 11 replies
  • 485 views
  • 0 likes
  • 7 in conversation