BookmarkSubscribeRSS Feed
thanikondharish
Calcite | Level 5

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

 

3 REPLIES 3
SASJedi
SAS Super FREQ

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

 

Check out my Jedi SAS Tricks for SAS Users
thanikondharish
Calcite | Level 5
I have a text in one RTF file so I have to read that text into sas and
create one dataset

text ---> This is awesome
SASJedi
SAS Super FREQ

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: 

Check out my Jedi SAS Tricks for SAS Users

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 406 views
  • 0 likes
  • 2 in conversation