BookmarkSubscribeRSS Feed
JRoman
Obsidian | Level 7

Hello,

 

When using PROC ODSTEXT's P statement with strings containing %SYSFUNC(URLENCODE(...)), I'm getting unexpected results in certain cases.

 

In particular, if the string being encoded has one or more digits and those digits are surrounded on both sides by a space, the digits and one of the spaces do not appear in the resulting text.

 

An example:

data foo;
  s  = urlencode('abc 123 xyz.txt');
  s2 = "%sysfunc(urlencode(abc 123 xyz.txt))";
run;

proc odstext data=foo;
  * First two work, third one loses the 123 and a space. ;
  p s;
  p s2;
  p "%sysfunc(urlencode(abc 123 xyz.txt))";

  * First one works, second one loses the 1 and a space. ;
  p "%sysfunc(urlencode(this works just fine))";
  p "%sysfunc(urlencode(this 1 has an issue))";
run;

proc_odstext_with_sysfunc_and_urlencode.PNG 

 

Is this the expected behavior?  As the above example illustrates, it is possible to work around this issue by storing the encoded text in a data set first, but it does not seem that such an approach should be necessary, should it?

 

This issue (or one very similar) appears to have also been encountered by @Quentin in this post.  In that case, the resolution was to use the URL style.  In my current case, that would not be applicable because the content I need to output is not being displayed as a clickable hyperlink to the user; rather, I am sending the content as a response from a stored process, and the client browser will be accessing the returned URL directly, without any interaction from the user.

 

I'm on SAS 9.4M5.

 

Thanks,

Jake

4 REPLIES 4
Patrick
Opal | Level 21

This feels like an undocumented feature worth raising with SAS TechSupport. If you do so please let us know the outcome.

JRoman
Obsidian | Level 7

Thanks for taking a look, @Patrick.  I just opened a ticket with Tech Support and will report back when I have more info.

Quentin
Super User

Agree this is a good one for tech support. 

 

It's interesting proc ODSTEXT works like you want when the value is read from a data set, but not when it's a literal value.  Could be a bug.

 

You can see it with just:

data foo;
  s  = 'this%201%20works';
run;

proc odstext data=foo;
  p s ;
  p 'this%201%20does%20not%20work';
run;

Returns  (9.4M4):

 

this%201%20works

this%20does%20not%20work

 

It looks like an alpha character or blank after the %201 and before then next % makes it work:

proc odstext data=foo;
  p 'this%201.%20does%not%20work';
  p 'this%201.123456789%20does%20not%20work';
  p 'this%201q%20does%20work';
  p 'this%201 %20does%20work';
  p 'this%201.1234q56789%20does%20work';
run;

Returns:

this%20does%not%20work

this%20does%20not%20work

this%201q%20does%20work

this%201 %20does%20work

this%201.1234q56789%20does%20work

 

Please do let us know what tech support says.

JRoman
Obsidian | Level 7

Thanks for those concise examples, @Quentin.

 

Tech Support confirmed there is indeed a defect leading to PROC ODSTEXT not properly handling certain string literals that contain URL-encoded text, and that the issue will hopefully be addressed in a future release.  (No version details at this time.)

 

In the meantime, three workarounds for the issue are:

1.) double the percent signs in the string literal,

proc odstext;
  p 'A%%201%%20B';
run;

 

2.) pass the non-encoded string literal to the URLENCODE function in the P statement, rather than calling %SYSFUNC(URLENCODE(...)) within the string literal,

proc odstext;
  p urlencode('A 1 B');
run;

 

3.) or store the encoded string in a data set variable and reference that variable in the P statement, rather than using a string literal.

data foo;
  s = urlencode('A 1 B');
run;
proc odstext data=foo;
  p s;
run;

 

All three of the above examples produce the same desired result:

A%201%20B

 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1901 views
  • 3 likes
  • 3 in conversation