Hello, I am creating a file that i am gonig to include in my proc report:
IT works until I want to open my links in a new tab.
Creating the compfile:
The problem is at the bottom where I want to make sure the Links will open in a new tab. Any help with this? been looking for some days now..
data _null_;
format num $2. cc $400. i 4. ;
filename compfile catalog 'work.tmp.compfile.source';
file compfile lrecl=500;
i=1;
do while (i le 25);
if (i ge 1) and (i le 9) then num = '0' || left(i);
else num = left(i);
cc = "compute _" || num || ";"; put cc;
cc = " if not notupper(substr(_" || num || ",1,1))"; put cc;
cc = " then call define (_col_,'style','style=[BACKGROUND=#A6CE39 FONT_WEIGHT=BOLD]');"; put cc;
cc = " else call define (_col_,'style','style=[BACKGROUND=#A9A9A9 FONT_WEIGHT=BOLD]');"; put cc;
cc = " if substr(_" || num || ",1,1) = '<'"; put cc;
cc = " then call define (_col_,'style','style=[BACKGROUND=#FFCC33 FONT_WEIGHT=BOLD]');"; put cc;
cc = 'url = "http://fabwtsdev.imec.be:8080/eDocStorageWebGui/Imec.eDoc.StorageWebGui.xbap?CtxFormat=CtxName;CtxVa...";';
put cc;
cc = "T = trim(substr(_" || num || ",1,1) || '"|| input(num,$2.) ||"');";
put cc;
cc = 'url_SP = url || "LotId;" || compress(LOT_ID) || ";Man;NoEdit;Operation;" || compress(Operation) || ";Man;NoEdit;DuploWaferId;" || compress(T) || ";Opt;Edit";';
put cc;
cc = 'if _'|| num || " ne '-' and not notupper(substr(_"|| num ||",1,1)) then CALL DEFINE(_COL_, 'URL', url_SP || '" target="_blank' );";
put cc;
cc = "endcomp;"; put cc;
i+1;
end;
run;
It does not look like you have the quoting for the target option right. You should be generating HTML that looks like
target="_blank"
Your code is:
CALL DEFINE(_COL_, 'URL', url_SP || '" target="_blank' );";
So it should probably be
CALL DEFINE(_COL_, 'URL', url_SP || '" target="_blank"' );;
it gives error on your way:
when i try:
then CALL DEFINE(_COL_, 'URL', url_SP || '" target="_blank"' );';
it gives:
ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, *, **, +, -, /, ;, <, <=, <>, =, >, ><, >=, AND, EQ, GE, GT, IN, LE, LT, MAX, MIN, NE, NG, NL, NOTIN, OR, ^=, |, ||, ~=.
Quoting still looks mismatched, but it is hard to tell. Can you paste in a copy of the generated code?
That should make it easier to tell if your code generation worked.
How are you calling the generated code?
Can you make a simplied version of the code (without this code generation step) that gets the URLs to open in a new tab/window?
You have a string that is quoted with double quotes (") that has embedded double quotes. You need to double the inner ones to get them to be treated as text instead of delimiters of the string.
Example:
put "Hello ""Sam"".";
I find that it is MUCH easier to use the PUT statement to generate code than to try and build it into strings.
I also find it much easier to use temporary files rather than source catalogs for code generation. You can look at them much easier and use them in more places.
I like to limit my line lengths to < 80 (really 72) so that both me and the computer can read the code more easily.
Here is a version of your program that is more "SASified".
filename compfile temp;
*filename compfile catalog 'work.tmp.compfile.source';
data _null_;
file compfile lrecl=500;
do i=1 to 25 ;
put
'compute _' i z2. ';'
/ 'if not notupper(substr(_' i z2. ',1,1)) then'
/ ' call define (_col_,"style","style=[BACKGROUND=#A6CE39 FONT_WEIGHT=BOLD]")'
/ ';'
/ 'else call define (_col_,"style","style=[BACKGROUND=#A9A9A9 FONT_WEIGHT=BOLD]");'
/ "if substr(_" i z2. ",1,1) = '<' then"
/ " call define (_col_,'style','style=[BACKGROUND=#FFCC33 FONT_WEIGHT=BOLD]')"
/ ';'
/ 'url = "http://fabwtsdev.imec.be:8080/eDocStorageWebGui/Imec.eDoc.StorageWebGui.xbap"'
/ ' || "?CtxFormat=CtxName;CtxValue;Optional;EditMode&Ctx=";'
/ "T = substr(_" i z2. ",1,1) || '" i z2. "';"
/ 'url_SP = url || "LotId;" || compress(LOT_ID) || ";Man;NoEdit;Operation;"'
/ ' || compress(Operation) || ";Man;NoEdit;DuploWaferId;" || compress(T) || ";Opt;Edit";'
/ 'if _' i z2. " ne '-' and not notupper(substr(_" i z2. ",1,1)) then"
/ " CALL DEFINE(_COL_, 'URL', url_SP || ' target=""_blank""' )"
/ ';'
/ "endcomp;"
;
end;
run;
I think that perhaps your issue is with the last CALL DEFINE statement.
Do you need to separate the URL from the TARGET= option somehow? Perhaps by using quote(trim(url_SP))?
You should test getting the syntax for this correct in a very simple example.
Did you mean this :
ods html file='c:\x.html' style=sasweb; proc report data=sashelp.class nowd ; columns sex age; define sex/ style={ HREFTARGET='_BLANK' }; compute sex; url='http://www.sas.com'; if sex='F' then call define(_col_,'url',url); endcomp; run; ods html close;
Ksharp
hi ksharp, i read your answer and it would be great if that worked.. but it does not for me?
define _01 / display width =80 style={HREFTARGET='_BLANK'} ;
define _02 / display width =80 style={HREFTARGET='_BLANK'} ;
result for _02: <td class="l Data" style=" font-weight: bold; background-color: #A6CE39;"><a href="http://winiis1.imec.be:8080/eDocStorageWebGui/Imec.eDoc.StorageWebGui.xbap?CtxFormat=CtxName;CtxValu...">D02</a>
so NO target=_blank to be seen..
is my define statement wrong?
Hi.
Counld This URL be opened by browser ? If it were , I think code is right.
ods html file='c:\x.html' style=sasweb; proc report data=sashelp.class nowd ; columns sex age; define sex/ style={ HREFTARGET='_BLANK' }; compute sex; length url $ 2000; url="http://www.google.com.hk/#hl=zh-CN&source=hp&q=http:%2F%2Ffabwtsdev.imec.&btnG=Google+%E6%90%9C%E7%B4%A2&oq=http:%2F%2Ffabwtsdev.imec.&aq=f&aqi=&aql=&gs_sm=s&gs_upl=9904l15080l1l16792l55l12l0l0l0l0l0l0ll0l0&bav=on.2,or.r_gc.r_pw.,cf.osb&fp=547ac8dddbfbbf18&biw=1024&bih=634 "; if sex='F' then call define(_col_,'url',url); endcomp; run; ods html close;
Ksharp
Ksharp
little remark in a sas context where macro language exists:
single quote is necessary for the url as you have many & MV resolution in action with the double quoting.
Andre
I had trouble with PROC REPORT in the past not combining STYLE settings. Your code is already setting style using call define.
Try adding the HREFTARGET tag to those style settings.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.