BookmarkSubscribeRSS Feed
Filipvdr
Pyrite | Level 9

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;

10 REPLIES 10
Tom
Super User Tom
Super User

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"' );;


Filipvdr
Pyrite | Level 9

it gives error on your way:

The SAS program did not produce any output.

when i try:

then CALL DEFINE(_COL_, 'URL', url_SP || '" target="_blank"' );';

it gives:

This request completed with errors.

ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, *, **, +, -, /, ;, <, <=, <>, =, >, ><, >=, AND, EQ, GE, GT, IN, LE, LT, MAX, MIN, NE, NG, NL, NOTIN, OR, ^=, |, ||, ~=. 

Tom
Super User Tom
Super User

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?

Tom
Super User Tom
Super User

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"".";

Tom
Super User Tom
Super User

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.

Ksharp
Super User

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

Filipvdr
Pyrite | Level 9

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?

Ksharp
Super User

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

Andre
Obsidian | Level 7

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

Tom
Super User Tom
Super User

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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 10 replies
  • 1414 views
  • 1 like
  • 4 in conversation