Hi all,
In ods html very easy hide link under some short label:
data input;
length pgmfield $500;
name="name1";
pgmfield= '<a href=http://translate.google.com/>'||name||'</a>';
output;
name="name2";
pgmfield= '<a href=http://google.com/>'||name||'</a>';
output;
name="name3";
pgmfield= '<a href=\\C:\...\test.docx>'||name||'</a>';
output;
run;
proc report data = input;
column name pgmfield;
define name/ noprint;
define pgmfield/' link_text';
run;
I need make the same in pdf, so in pdf document create link also possible:
data input;
length lnk pgmfield $500;
name="name1";
path="http://translate.google.com";
output;
name="name2";
path="\\C...\test.docx>";
output;
name="name3";
path="http://translate.google.com/";
output;
run;
ods pdf file='...test.pdf';
proc report data = input;
column name path ;
define name/ noprint;
define lnk/' lnk ';
compute path;
Call Define(_col_,'Url',path);
endcomp;
run;
ods pdf close;
But how to hide full url(or path to some file) under short name(label) as it was in first example(ods html)?
Thanks!
Hi,
I guess I'm not entirely sure what it is that you are trying to do. However, the program below shows how to assign a URL to a cell based on the value of another cell using PROC REPORT. I don't see, in your example, what the value of the LNK variable is; I only see the value being assigned to the PATH variable. In fact, I see that you have LNK on the report, but do not see that you ever assign LNK a value or have it in the COLUMN statement, which should be generating an error message, so I'm not sure that your code, as posted will work. I would expect you to see a warning message similar to this:
WARNING: LNK is not in the report definition.
NOTE: Variable LNK is uninitialized.
Here's the program. I'm not sure you need a data step to create the INPUT dataset or the PATH variable. You could do it several different ways, but the program only shows 2 of them.
cynthia
ods listing close;
*** Method 1: Use Call DEFINE;
ods pdf file='c:\temp\test_url1.pdf';
proc report data = sashelp.class(obs=3) nowd;
title '1) Click on the AGE column to follow the link';
column name sex age height weight ;
define sex / 'Gender';
compute age;
if sex = 'F' then
Call Define(_col_,'Url','http://maps.google.com');
else if sex = 'M' then
Call Define(_col_,'Url','http://support.sas.com/resources/papers/proceedings11/246-2011.pdf');
endcomp;
run;
ods pdf close;
** Method 2: Use a format;
proc format;
value $lnk 'Maps'='http://maps.google.com'
'Paper' = 'http://support.sas.com/resources/papers/proceedings11/246-2011.pdf'
;
run;
ods pdf file='c:\temp\test_url2.pdf';
proc report data = sashelp.class(obs=3) nowd;
title '2) Click on the LINK column to follow the link';
column name sex age LINK ;
define sex / 'Gender';
define LINK / COMPUTED
style(column)={url=$lnk.};
compute link / character length=5;
if sex = 'F' then
link = 'Maps';
else if sex = 'M' then
link = 'Paper';
endcomp;
run;
ods pdf close;
Hi,
I guess I'm not entirely sure what it is that you are trying to do. However, the program below shows how to assign a URL to a cell based on the value of another cell using PROC REPORT. I don't see, in your example, what the value of the LNK variable is; I only see the value being assigned to the PATH variable. In fact, I see that you have LNK on the report, but do not see that you ever assign LNK a value or have it in the COLUMN statement, which should be generating an error message, so I'm not sure that your code, as posted will work. I would expect you to see a warning message similar to this:
WARNING: LNK is not in the report definition.
NOTE: Variable LNK is uninitialized.
Here's the program. I'm not sure you need a data step to create the INPUT dataset or the PATH variable. You could do it several different ways, but the program only shows 2 of them.
cynthia
ods listing close;
*** Method 1: Use Call DEFINE;
ods pdf file='c:\temp\test_url1.pdf';
proc report data = sashelp.class(obs=3) nowd;
title '1) Click on the AGE column to follow the link';
column name sex age height weight ;
define sex / 'Gender';
compute age;
if sex = 'F' then
Call Define(_col_,'Url','http://maps.google.com');
else if sex = 'M' then
Call Define(_col_,'Url','http://support.sas.com/resources/papers/proceedings11/246-2011.pdf');
endcomp;
run;
ods pdf close;
** Method 2: Use a format;
proc format;
value $lnk 'Maps'='http://maps.google.com'
'Paper' = 'http://support.sas.com/resources/papers/proceedings11/246-2011.pdf'
;
run;
ods pdf file='c:\temp\test_url2.pdf';
proc report data = sashelp.class(obs=3) nowd;
title '2) Click on the LINK column to follow the link';
column name sex age LINK ;
define sex / 'Gender';
define LINK / COMPUTED
style(column)={url=$lnk.};
compute link / character length=5;
if sex = 'F' then
link = 'Maps';
else if sex = 'M' then
link = 'Paper';
endcomp;
run;
ods pdf close;
Hi Cynthia,
Regarding small issue in examples in my code-yes, you are right, LNK should be replaced to Path etc., I just accidentally put wrote column names when typed second example.
And your example is exactly what I need:)
Thanks!
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.