需要填充SAS变量中的空格

发布于 2025-01-03 08:36:42 字数 217 浏览 2 评论 0 原文

看到这里就有点愣住了。

我有一个具有不同长度值的 SAS 变量。

如果变量所需的内存低于阈值(48 字节),我会向变量附加空格,以便它达到该内存分配。

我该如何在 SAS 中执行此操作?

更重要的是,在哪里可以找到有关 SAS 中单个空格(或任何其他字符/类型)占用的内存的文档?

编辑: stevepastelan 的回答实际上很完美:)

Slightly stunned here.

I have a SAS variable that has values of varying lengths.

If the memory required for the variable is below a threshold(48bytes), I have the append white spaces to the variable so that it reaches that memory allocation.

How would I do this in SAS?

More importantly, where can I find documentation regarding the memory taken up by a single white space(or any other character/type) in SAS?

Edit:
stevepastelan's answer was perfect actually :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

半﹌身腐败 2025-01-10 08:36:42

SAS 中的字符变量会自动填充到右侧以填充其长度,但是某些语句(例如 PUT 语句)可能会在显示时修剪它们。

您可以使用格式强制输出,例如:

data test;
    length x $ 8;    

    x = "XX";   
    put "1) " x     "END"; /* Omitting the format will trim the printed variable value */    
    put "2) " x $8. "END"; /* Now it's shown as right-padded */


    x = "123456789";       /* The extra character is truncated from the variable */
    put "3) " x $8. "END";             
    put "4) " x $9. "END"; /* increasing format width will add extra right padding */
    put "5) " x $6. "END"; /* A shorter format will truncate the display */
run; 

将以下内容写入 SAS 日志:

1) XX END
2) XX      END
3) 12345678END
4) 12345678 END
5) 123456END

Character variables in SAS are automatically padded to the right to fill their length, however, certain statements, such as the PUT statement, may trim them when displaying.

You can use formats to force the output, ex:

data test;
    length x $ 8;    

    x = "XX";   
    put "1) " x     "END"; /* Omitting the format will trim the printed variable value */    
    put "2) " x $8. "END"; /* Now it's shown as right-padded */


    x = "123456789";       /* The extra character is truncated from the variable */
    put "3) " x $8. "END";             
    put "4) " x $9. "END"; /* increasing format width will add extra right padding */
    put "5) " x $6. "END"; /* A shorter format will truncate the display */
run; 

Writes the following to the SAS log:

1) XX END
2) XX      END
3) 12345678END
4) 12345678 END
5) 123456END
廻憶裏菂餘溫 2025-01-10 08:36:42

我想不出在什么情况下你会想要这样做。您能否详细说明一下原因,以启发我们。同时,这应该为您提供所需的内容:

http://support .sas.com/resources/papers/proceedings09/010-2009.pdf

除非我读错了,否则 Itzy 是对的。它们是固定长度变量,因此 20 个字节的长度存储在内存中时将占用 20 个字节。

如果需要填充值,可以使用重复功能:

http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000245939.htm

I cant think of any circumstances in which you would want to do that. Can you elaborate on the why to enlighten us. In the meantime this should provide you with what you require:

http://support.sas.com/resources/papers/proceedings09/010-2009.pdf

Unless I've misread it then Itzy is right. They are fixed length variables so a length of 20 bytes will take up 20 bytes when stored in memory.

If you need to pad a value you can use the repeat function:

http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000245939.htm

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文