sas - 为什么 PROC FCMP 函数总是返回 33 个字节而不是更多?

标签 sas fcmp

我通过 PROC FCMP 定义了以下函数。代码的要点应该非常明显并且相对简单。我从一行 XHTML 中返回一个属性的值。这是代码:

proc fcmp outlib=library.funcs.crawl;
    function getAttr(htmline $, Attribute $) $;

       /*-- Find the position of the match --*/
    Pos = index( htmline , strip( Attribute )||"=" );

       /*-- Now do something about it --*/
       if pos > 0 then do;
          Value = scan( substr( htmline, Pos + length( Attribute ) + 2), 1, '"');
       end;
       else Value = "";
       return( Value);
    endsub;
run;

无论我用 length 或 attrib 语句做什么来尝试显式声明返回的数据类型,它总是只返回最多 33 个字节的请求字符串,无论实际有多长返回值是。无论我正在搜索哪个属性,都会发生这种情况。数据步骤中的相同代码(硬编码)会返回正确的结果,因此这与 PROC FCMP 相关。

这是我用来测试它的数据步骤(其中 PageSource.html 是任何具有 xhtml 兼容属性的 html 文件——完全引用):

data TEST;
length href $200;
infile "F:\PageSource.html";

input;

htmline = _INFILE_;

href = getAttr( htmline, "href");
x = length(href);

run;

更新:这似乎在升级到 SAS9.2 - 第 2 版后正常工作

最佳答案

我认为问题(虽然我不知道为什么)在扫描函数中——它似乎截断了 substr() 的输入。如果您从 scan() 中提取 substr 函数,将 substr 函数的结果分配给一个新变量,然后将其传递给 scan,这似乎可行。

这是我运行的:

proc fcmp outlib=work.funcs.crawl;
    function getAttr(htmline $, Attribute $) $;
    length y $200;
       /*-- Find the position of the match --*/
    Pos = index( htmline , strip( Attribute )||"=" );

       /*-- Now do something about it --*/
       if pos > 0 then do;
          y=substr( htmline, Pos + length( Attribute ) + 2);
          Value = scan( y, 1, '"');       
       end;
       else Value = "";
       return( Value);
    endsub;
run;

options cmplib=work.funcs;

data TEST;
length href $200;
infile "PageSource.html";

input;

htmline = _INFILE_;
href = getAttr( htmline, "href");
x = length(href);
run;

关于sas - 为什么 PROC FCMP 函数总是返回 33 个字节而不是更多?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1032238/

相关文章:

android - 当应用程序处于后台或被杀死时 FCM onMessageReceived() 未调用

sas - Proc FCMP - 默认参数值

在 SAS 中导入 Access DB 文件但失败

c - 编译的 .exe 找不到输入文件

.net - 用于单字节字符语言的 Microsoft .Net framework 4.0

sql - 我需要一种方法来查找一行是否有值,如果有,那么我需要根据另一个值对所有行进行分组

sas - 如何在 SAS 中创建数据透视表?

parameters - 如何定义具有不同数量参数的函数?