BookmarkSubscribeRSS Feed
RichardAD
Quartz | Level 8

Base SAS has the HTMLENCODE() function, and there is not the same available to Proc DS2, nor Proc FCMP.

The HTTP package does not seem to have anything to do the same.

Is there any way to trick DS2 into using HTMLENCODE?

 

Example:

The node name needs to be html-encoded in certain situations

%let MAX_LEN_PART = 200 ;
proc ds2 ;
  package sasuser.Node / overwrite=yes ;
    declare varchar(512) name newname ;
    declare package sasuser.Node parent ;
    declare package sasuser.Node children ;
    declare package sasuser.Node next ;
  
    method init() ;
      alias_counter = 0 ;
    end ;
  
    method Node(varchar(512) name, package sasuser.Node parent, in_out double alias_count) ;
      this.name = name ;
      this.newname = name ;
      this.parent = parent ;
      if verify(name,'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789 !#$%&''()+,-.;=@[]^`{}~/') then do ;
        this.newname = htmlencode(name, '7bit') ;
        put newname= ;
      end ;
      if length(this.newname) > &MAX_LEN_PART then do ;
        alias_count + 1 ;
        this.newname = '_migrate_' || put(alias_counter,z4.) ;
        put newname= ;
      end ;
    end ;

    method Node(varchar(512) name) ;
      this.name = name ;
    end ;

    method get_path() returns varchar(4096) ;
      if null(parent)
        then return name ; 
        else return parent.get_path() || '/' || name ;
    end ;
  endpackage /* Node */;
  
  data _null_;
  enddata;
  run ;
quit ;

But the log shows:

ERROR: Compilation error.
ERROR: Unknown function htmlencode.
NOTE: PROC DS2 has set option NOEXEC and will continue to prepare statements.
1 REPLY 1
ChrisNZ
Tourmaline | Level 20

The list of DS2 functions is here. You can add a suggestion if you want more functions supported.

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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
  • 1 reply
  • 540 views
  • 0 likes
  • 2 in conversation