BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
pareenakalaria
Calcite | Level 5

I use Proc report to create TOC that has URL link to table within same PDF document using anchor= option. I use Do loop from 1 to 150 to set an incremental anchor for table created thru proc report ran within that loop.

Anchor works perfectly fine and create Url within TOC for anchors 1 thru 9 but does not create URL for 10th and after. It starts working again starting at 91st anchor till 99th anchor.

After lot of research found a documentation on SAA that says not all anchor values are valid. I am trying to understand why would anchor work for 1 to 9 and again 91 thru 99 and not work for any other values.

Is there a way to fix this problem? Can you please help.

DATA &filename._V1 (drop = num);
length TAG $5.;
RETAIN NUM;
SET &filename._V0;
NUM+1;
TAG=strip(cats('T',put(NUM,3.)));
RUN;

PROC TRANSPOSE DATA = &filename._V1 OUT = &filename._V2 (rename = (_name_ = METRIC col1=VALUE));
BY DESCENDING OBJECTIVE METRIC_NAME TAG;
VAR METRIC_FORMULA METRIC_DEFINITION_1	METRIC_DEFINITION_2	INCLUDE_EXCLUDE	RELEVANT_OTHER	TARGET_METHOD EG PRIMARY_LEVEL SECONDARY_LEVEL;
RUN;		

PROC SQL; CREATE TABLE &filename._V3 AS
SELECT OBJECTIVE, METRIC_NAME, TAG
,CASE WHEN METRIC = 'METRIC_FORMULA' THEN 'Metric Formula'
	WHEN METRIC = 'METRIC_DEFINITION_1' THEN 'Metric Definition - Numerator'
	WHEN METRIC = 'METRIC_DEFINITION_2' THEN 'Metric Definition - Denominator'
	WHEN METRIC = 'INCLUDE_EXCLUDE' THEN 'Inclusion / Exclusion'
	WHEN METRIC = 'RELEVANT_OTHER' THEN 'Additional notes'
	WHEN METRIC = 'TARGET_METHOD' THEN 'Target Method'
	WHEN METRIC = 'EG' THEN 'Experience Group'
	WHEN METRIC = 'PRIMARY_LEVEL' THEN 'KR Level - Primary'
	WHEN METRIC = 'SECONDARY_LEVEL' THEN 'KR Level - Secondary'
	else METRIC END AS METRIC
,VALUE
FROM &filename._V2
;QUIT;

PROC SQL; CREATE TABLE &filename._TOC AS 
SELECT DISTINCT OBJECTIVE, METRIC_NAME, TAG, strip(cats("#",TAG)) as RTAG length = 6 
FROM &filename._V3
ORDER BY OBJECTIVE DESC, METRIC_NAME, TAG
;QUIT;

OPTIONS NOCENTER ORIENTATION = PORTRAIT NODATE PAGENO = 1 NONUMBER NOBYLINE 
		TOPMARGIN = 0.5IN BOTTOMMARGIN = 0.8IN LEFTMARGIN = 0.8IN RIGHTMARGIN = 0.8IN;
TITLE;
FOOTNOTE;
ODS PDF FILE = 'TEST.PDF' 
					STYLE=PRINTER
					STARTPAGE = BYGROUP
					ANCHOR='REP'
					UNIFORM NOTOC
					; 
ODS ESCAPECHAR ='^';
FOOTNOTE1 J=R 	COLOR ='#0077B2' HEIGHT=2 FONT = ARIALBLACK '^{THISPAGE}';
FOOTNOTE2 J =L 	COLOR ='#0077B2' 
				HEIGHT=5 FONT = ARIALBLACK bold 'KP DIGITAL	'  
				HEIGHT=2 FONT = ARIAL '	Digital Dashboard' 
				HEIGHT=3 BOLD FONT = ARIALBLACK ' | Metrics Definitions';
ODS TEXT = '^S={just=C fontsize=35pt background=#1A3C6F color=white width=100pct} Metrics Definition';
ODS TEXT = '^S={just=C fontsize=10pt background=white color=white} ';
ODS TEXT = '^S={just=R 
				preimage="/gpfsFS2/sasdata/adhoc/po/dec/da/data5/Portfolio_view/data/Qualtrics Survey Button.png" 
				url="https://kp.co1.qualtrics.com/jfe/form/SV_eWZagVi59I2vLsW"}';
ODS TEXT = '^S={just=C fontsize=10pt background=white color=white} ';
ODS TEXT = '^S={just=C fontsize=20pt background=white color=#1A3C6F font_weight=BOLD} Table of Contents^n';

PROC REPORT DATA = &FILENAME._TOC NOWD SPLIT = ' ' NOHEADER MISSING;
TITLE3 J=CENTER BCOLOR=WHITE COLOR='#1A3C6F' HEIGHT=5 BOLD 'Table of Contents';
COLUMN RTAG OBJECTIVE METRIC_NAME ;
DEFINE RTAG /NOPRINT ;
DEFINE METRIC_NAME /GROUP;
DEFINE OBJECTIVE /NOPRINT GROUP ORDER ORDER = DATA;
BREAK AFTER OBJECTIVE / SKIP SKIP;
COMPUTE BEFORE OBJECTIVE/ STYLE =[JUST=L BACKGROUND=#1A3C6F FONT_SIZE=12PT FOREGROUND=WHITE FONT_WEIGHT=BOLD textdecoration=underline];
LINE OBJECTIVE $100.;
ENDCOMP;
COMPUTE METRIC_NAME;
/* RTAG = "#"||(TAG);*/
/* RTAG = cats("#",trim(TAG));*/
CALL DEFINE(_COL_,'URL',RTAG);
ENDCOMP;
RUN;

ods pdf startpage=now ;

%MACRO PDF_TABLE(); 
%LOCAL I;

PROC SQL NOPRINT;
SELECT COUNT(METRIC_NAME)  INTO :MCNT
FROM &FILENAME._TOC;
QUIT;

%DO I = 1 %TO &MCNT;

ODS PDF ANCHOR="T&I.";

PROC REPORT DATA = &filename._V3 (WHERE=(TAG=%sysfunc(quote(T&I.,%str(%')))))
STYLE(Header)={background=charcoal foreground=white }
STYLE(column)={background=white foreground=black}
STYLE(report)=[rules=all bordercolor=charcoal width=100%];

TITLE1 LINK = '#REP' J=LEFT BCOLOR='CHARCOAL' COLOR=WHITE HEIGHT=5 FONT= ARIAL '>BACK';
TITLE2 HEIGHT=5 BCOLOR='white' COLOR=WHITE;
TITLE3 J=LEFT BCOLOR='#1A3C6F' COLOR=WHITE HEIGHT=5 FONT=ARIAL 'Objective:     	#byval(objective)';

BY DESCENDING OBJECTIVE METRIC_NAME ;

COLUMN OBJECTIVE METRIC_NAME METRIC VALUE;

DEFINE OBJECTIVE /noprint;
DEFINE METRIC_NAME / group noprint ;
DEFINE METRIC / '' ;
DEFINE VALUE / '';

COMPUTE BEFORE _PAGE_ / STYLE = [BACKGROUND=#0077B2 COLOR=WHITE FONTSIZE=5];
	LINE @1 'KR / METRIC: ' @15 METRIC_NAME $150. ;
ENDCOMP;

BREAK AFTER METRIC_NAME / PAGE ;

RUN;
%END;
%MEND PDF_TABLE;
%PDF_TABLE();

ODS PDF CLOSE;

 

1 ACCEPTED SOLUTION

Accepted Solutions
RichardAD
Obsidian | Level 7

You can try using leading zero suffixes.  T01 to T99 and '#T'||put(_N_,z2.) in Proc REPORT.

View solution in original post

5 REPLIES 5
Tom
Super User Tom
Super User

Is it a little hard to figure out what you are saying you are having trouble with.  It is a little hard to follow all of that code.  It sounds like you are trying to generate a PDF file with anchors by doing something like:

 

ods pdf anchor="T1";
proc ....
ods pdf anchor="T2";
proc ....
ods pdf anchor="T3";
proc ....

Does that work? Can you tell if the anchors are created in the PDF file?

 

But perhaps you are actually talking about the COMPUTE block in your PROC REPORT code?  That code looks fishier than the code that is generating the ODS PDF ANCHOR statements.

 

COMPUTE METRIC_NAME;
/* RTAG = "#"||(TAG);*/
/* RTAG = cats("#",trim(TAG));*/
CALL DEFINE(_COL_,'URL',RTAG);
ENDCOMP;

What is the code in the comments doing? What does RTAG have in it?  Are you trying to generate something like '#T1' or '#T2'?

 

 

Can you create a simpler example without all of the macro code that exhibit the same issue?

pareenakalaria
Calcite | Level 5

RTAG has #T1, #t2, #T3 etc. My anchors work perfectly fine until it reaches T9. URL link for 10th metric doesnt work. It would be easier to understand if you click on each metric in the Table of Content on first page within PDF file. 

Tom
Super User Tom
Super User

The ANCHOR= option seems to be working fine for me.

filename code temp;

data test;
  file code ;
  set sashelp.class;
  length anchor $10 ;
  anchor=cats('#T',_n_);
  put 'ods pdf anchor="T' _n_ +(-1) '";'
    / 'proc report data=test(obs=' _n_ 'firstobs=' _n_ ');'
    / 'compute anchor; call define(_col_,"URL",anchor);endcomp;'
    / 'run;'
  ;
run;

ods pdf file='C:\downloads\testing.pdf';
%include code / source2;
ods pdf close;
pareenakalaria
Calcite | Level 5

I tested your code and and I see same problem. It woks fine for #T1 thru #T9 but all anchors after that (#T10 thru #T19) doesn't work.

RichardAD
Obsidian | Level 7

You can try using leading zero suffixes.  T01 to T99 and '#T'||put(_N_,z2.) in Proc REPORT.

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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
  • 5 replies
  • 1645 views
  • 0 likes
  • 3 in conversation