My query is like we have one rtf file . So just i checked manually like 10 pages are there .
how to do in sas code to find the no.of pages in rtf file
Not all applications that create RTF files store the number of pages in the document metadata. But if the RTF you are working with was created in Microsoft Word, that information is available as metadata in the RTF file and you can extract it like this:
data rtfinfo;
Length Author $50 Pages Words 8;
if _n_=1 then do;
rxAuthor=prxparse('!\\author\s?([^}]*)}!');
rxDate=prxparse('!\\creatim\s?\\yr(\d*)\\mo(\d*)\\dy(\d*)!');
rxPages=prxparse('!\\nofpages\s?(\d*)}!');
rxWords=prxparse('!\\nofwords\s*(\d*)}!');
end;
retain rx:;
drop rx:;
infile 'C:\temp\myrtf.rtf' end=eof;
do until (eof);
input;
if prxmatch(rxAuthor,_infile_) then do;
Author=prxposn(rxAuthor,1,_infile_);
put Author=;
end;
if prxmatch(rxPages,_infile_) then do;
Pages=input(prxposn(rxPages,1,_infile_),32.);
put Pages=;
end;
if prxmatch(rxWords,_infile_) then do;
Words=input(prxposn(rxWords,1,_infile_),32.);
put Words=;
end;
if sum(missing(Author),missing(Pages),missing(Words))=0 then do;
output;
stop;
end;
end;
run;
This code produces an output that looks like this:
Obs | Author | Pages | Words |
---|---|---|---|
1 | Mark Jordan | 4 | 16 |
RTF is a format designed to present information best formatted for human consumption and is not well suited for machine-reading. Significant SAS programming and a good knowledge of RTF structure are required to extract data from an RTF. Here are some good references to get you started:
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.