DATA Step, Macro, Functions and more

Reading a messy string.

Occasional Contributor
Posts: 5

Reading a messy string.

[ Edited ]

I have a variable that is named Units.  Some of the values the variable takes on are:


x10E3/uL   ---------> /* means "times 10000/uL"   It is in E notation here. */



As you can see there is a mix of letters and numbers as well as slashes in the 2 observations. How can I tell SAS to read the entire string from a raw data file?


I also have another variable named Interval with values such as:

3.4 - 10.8

4.14 - 5.80


How can I read these from a raw data file as well?




Trusted Advisor
Posts: 1,147

Re: Reading a messy string.

Consider it as a character variable and it should read the entire string.

Please let me know if it is not clear.

Also let us know how are you importing the raw data file.
Super User
Posts: 23,754

Re: Reading a messy string.

You tell SAS to use a specific delimiter or to read for a specific length. 


Given what you've posted we can't really suggest solutions beyond this. Reading a text file can be complicated or easy, it depends on multiple factors and we only have a minimal idea of your issue. 


If you'd like further help please post sample data that accurately reflects your situation. 

Esteemed Advisor
Posts: 5,535

Re: Reading a messy string.

[ Edited ]

The only difficulty is the dash between the range values. Use pointer control (here +1) to skip it.


data abc;
length units $12;
input id rangeLow +1 rangeHigh units :$12.;
1 3.4 - 10.8 x10E3/uL
100 4.14 - 5.80 mL/min/1.73

proc print; run;
Super Contributor
Posts: 474

Re: Reading a messy string.



To acces the input buffer (whole line of the file) use the automatic variable _INFILE_


data WANT;
        infile "<myfile>" lrecl=200;
        put _INFILE_;

You can also check the following paper by Howard Schreier:


Daniel Santos @

Super User
Posts: 13,563

Re: Reading a messy string.

What type of file are you reading from? Most delimited files such as CSV should handle this easily though unmatched quotes might cause other problems. Fixed column has no problem as long as the correct variable type is assigned.

Ask a Question
Discussion stats
  • 5 replies
  • 6 in conversation