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.

BASUG is hosting free webinars Next up: Mark Keintz presenting History Carried Forward, Future Carried Back: Mixing Time Series of Differing Frequencies on May 8. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.
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

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 4 replies
  • 1002 views
  • 3 likes
  • 3 in conversation