URLENCODE Function

Returns a string that was encoded using the URL escape syntax.

Category: Web Tools
Restriction: I18N Level 2 functions are designed for use with SBCS, DBCS, and MBCS (UTF8).

Syntax

URLENCODE(argument)

Required Argument

argument

specifies a character constant, variable, or expression.

Details

Length of Returned Variable in a DATA Step

If the URLENCODE function returns a value to a variable that has not previously been assigned a length, then that variable is given a length of 200 bytes.

The Basics

argument can be encoded using either SAS session encoding or UTF-8 encoding. To encode argument by using the SAS session encoding, set the system option URLENCODING=SESSION. To encode argument by using UTF-8 encoding, set the system option URLENCODING=UTF8.
The URLENCODE function encodes characters that might otherwise be significant when used in a URL. This function encodes all characters except for the following:
  • all alphanumeric characters
  • dollar sign ($)
  • hyphen (-)
  • underscore ( _ )
  • at sign (@)
  • period (.)
  • exclamation point (!)
  • asterisk (*)
  • open parenthesis ( ( )and close parenthesis ( ) )
  • comma (,).
Note: The encoded string might be longer than the original string. Ensure that you consider the additional length when you use this function.

Example

The following SAS statements produce these results using SAS session encoding.
SAS Statement
Result
x1=urlencode ('abc def');
put x1;
  
abc%20def
x2=urlencode ('why?');
put x2;
  
why%3F
x3=urlencode ('ABC#1');
put x3;
  
ABC%231

See Also

Functions:
System Options:
URLENCODING= System Option in SAS System Options: Reference