DATA Step, Macro, Functions and more

Reading a messy string.

Reply
New Contributor
Posts: 4

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. */

mL/min/1.73

 

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,137

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.
Thanks,
Jag
Super User
Posts: 19,789

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. 

Respected Advisor
Posts: 4,920

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.;
datalines;
1 3.4 - 10.8 x10E3/uL
100 4.14 - 5.80 mL/min/1.73
;

proc print; run;
PG
Super Contributor
Posts: 474

Re: Reading a messy string.

Hi.

 

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

 

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

You can also check the following paper by Howard Schreier: http://www.lexjansen.com/nesug/nesug01/cc/cc4018bw.pdf

 

Daniel Santos @ www.cgd.pt

Super User
Posts: 11,343

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
  • 224 views
  • 0 likes
  • 6 in conversation