Hi
I have a problem with infile statement, it's very basic:
filename fin "&_we." encoding=utf8 lrecl=10000;
filename fout "&_wy." encoding=utf8 lrecl=10000;
data res;
length oneline $10000;
infile fin dlm='****' encoding=utf8;
file fout encoding=utf8;
input oneline $10000. @@;
run;
Unfortunately it omits the first line from XML file.
Do you have any idea why?
Thank you!
You define your filenames with variable record lengths, and then force-read 10000 bytes. If the first line is less than that in length, SAS will set the variable to missing and skip to the next line. Use the truncover option in the infile statement.
What kind of XML file are you reading?
Double trailing AT @@ and truncover are causing infinite loop.
@Dontik wrote:
"TRUNCOVER enables you to read variable-length records when some records are shorter than the INPUT statement expects. Variables without any values assigned are set to missing."
Thank you, that makes sense, unfortunately using truncover makes infile statement very slow.. In fact, 10 minutes later it's still running..
What do you want to know about my XML file?
Yeah, the truncover and @@ will cause problems. Good catch of my foul ball, @data_null__ !
Try to get a feel for your infile.
Do something like this:
data _null_;
infile fileref end=eof;
retain maxlen 0;
maxlen = max(maxlen,length(_infile_));
if eof then do;
call symputx('maxlen',maxlen);
call symputx('recnum',_n_);
end;
run;
to see how large your lines are and how many you have to read.
It is skipping the first line because you asked SAS to read 1000 bytes. If the first line doesn't have enough characters then the INPUT statement will flow to the next line and read from there instead.
Using formatted input with double trailing @ does not seem right.
Your variable names make it look like you want to read the data line by line. So just use TRUNCOVER option on INFILE and remove the trailing @@.
data res;
length oneline $10000;
infile fin dlm='****' encoding=utf8 truncover;
file fout encoding=utf8;
input oneline $10000. ;
put oneline;
run;
Or use a bare INPUT statement and copy the text of the line form the automatic variable _INFILE_.
data res;
infile fin dlm='****' encoding=utf8 truncover;
file fout encoding=utf8;
input;
put _infile_;
run;
If you want to read that data term by term then use list mode input instead.
data res;
length oneword $10000;
infile fin dlm='****' encoding=utf8 ;
file fout encoding=utf8;
input oneword @@ ;
put oneword @;
run;
Also why are you using * as your delimiter character (default is space)? And then why do you list if four times? If you want to use four * next to each other as the delimiter then you need to use DLMSTR= option instead of DLM= option. When you list multiple characters in the DLM= option each one is treated as a possible delimiter.
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.
Ready to level-up your skills? Choose your own adventure.