BookmarkSubscribeRSS Feed
thummala
Obsidian | Level 7

Hi,

 

Can you please help me in figuring out the code for below scenario.

 

I have a variable with pagenumbers. I want these numbers to be hyperlinked to an external file. When there are one page numebr in the variable then there are no issues. But when there are multiple page numbers not sure how to code it.

 

pages
14
12, 15
8, 14, 20, 30, 32, 35

 

 

 

 

if index(pages,',')=0 then pg_=strip(pages);
else if index(pages,',') then do;
    pg_=substr(pages, 1, index(pages,','));
    pg1_= substr(pages,index(pages,',')+1);
end;
 
if pages ne '' and index(pages, ',')=0 then origin = '{CRF {\field {\*\fldinst HYPERLINK "\\blankcrf.pdf#page=' ||
trim(left(pg_)) || '"}{\fldrslt {\cs15\cf2 Page ' || trim(left(pg_)) || '}}}}';
else if pages ne '' and countc(pages, ',')=1 then origin = '{CRF {\field {\*\fldinst HYPERLINK "\\blankcrf.pdf#page=' ||
trim(left(pg_)) || '"}{\fldrslt {\cs15\cf2 Pages ' || trim(left(pg_)) || '}}}}' ||'{{\field {\*\fldinst HYPERLINK "\\blankcrf.pdf#page=' ||
trim(left(pg1_)) || '"}{\fldrslt {\cs15\cf2 ' || trim(left(pg1_)) || '}}}}';
 
else if pages ne '' and countc(pages, ',') gt 1 then origin='{Multiple CRF {\field {\*\fldinst HYPERLINK "\\blankcrf.pdf#page=1"}{\fldrslt {\cs15\cf2 Pages}}}}';

 

Can anyone help me in looping it n number of times based on the page numbers so that all the pages can be hyperlinked and I can replace the "Multiple CRF" value when there are more than two pages in the pages variable.

 

 

Thank You for your time.

1 REPLY 1
RW9
Diamond | Level 26 RW9
Diamond | Level 26

I would advise you simplfy your question as I really don't want to start looking through RTF code and such like.  If you want to loop over those values, then use a do loop (and maybe an array if necessary) e.g;

data want;
  do i="14","12, 15","8, 14, 20, 30, 32, 35";
    ...do something here e.g...
    page="Some page number="||strip(i);
  end;
run;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

Discussion stats
  • 1 reply
  • 944 views
  • 0 likes
  • 2 in conversation