02-28-2013 09:10 AM
I'm trying to load a .txt file into SAS, and have created two separate load files. One that looks at variable1A and the other, variable 1B. However, both variable1A and variable1B are in the same .txt file. The only way to separate the two is that variable 1A has a shorter record length than variable 1B. Is there a way to load the file so that only those records with variable1A (with say a maximum record length of 200) are in one SAS dataset, and then those variables with a reclen that exceed 200 are in another SAS dataset?
02-28-2013 09:18 AM
Yes. Use the LENGTH option in the INFILE statement. Example 4 in the reference documentation may be helpful
In general, something like this might work
FILENAME indata 'mydata.txt' LENGTH=linelen;
DATA A B;
IF linelen=<onevalue> then output a;
ELSE IF linelen=<othervalue> THEN OUTPUT b;
ELSE <put error message>;
02-28-2013 09:20 AM
Without example data it is difficult to provide a working suggestion. You can use the infile option "length=" to specify a variable, in your infile statement, that will capture each record's length (e.g., infile "c:\mydata.txt" length=reclen).
That way you can create both files in one pass. e.g., pseudo code:
data long short;
infile "c:\mydata.txt" length=reclen;
input variable $varying500.;
if reclen gt 200 then output long;
else output short;
02-28-2013 09:23 AM
Ashley, it would be helpful to know how you are reading in the text file. Can you do a simple length statement on both 1A and 1B then compare the lengths?
if (a < b) or (a<200) then output short;
if (b > a) or (b>200) then output long;