BookmarkSubscribeRSS Feed
data_null__
Jade | Level 19
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_;
11 REPLIES 11
Ksharp
Super User
Hi, data _null_;
you try this.

[pre]
data temp;
input sex $upcase1.;
datalines;
F
m
m
M
f
f
F
;
[/pre]
data_null__
Jade | Level 19
I see I wasn't clear. I want to use @'string' in an INPUT statement and ignore case.
Ksharp
Super User
Sorry. not understand your mean.
Patrick
Opal | Level 21
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
data_null__
Jade | Level 19
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)).
ArtC
Rhodochrosite | Level 12
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]
data_null__
Jade | Level 19
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.
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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.
ArtC
Rhodochrosite | Level 12
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.
Peter_C
Rhodochrosite | Level 12
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
SASKiwi
PROC Star
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!

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 11 replies
  • 2220 views
  • 1 like
  • 7 in conversation