【问题标题】:SAS DDE not formatting output correctly in ExcelSAS DDE 未在 Excel 中正确格式化输出
【发布时间】:2014-04-26 05:33:27
【问题描述】:

我只是想将 SAS 数据集导出到预制的 Excel 模板中。

我的数据集(这是一个 .wpd 文件)的前 6 个变量如下所示:

StartDate     EndDate    product_code   Description               Leaflet    Media
04-Jul-13    07-Jul-13    256554    BUTCHER BEEF 1PK (1 KGM)       54x10        3   

我目前有:

options noxwait noxsync;
x '"c:\Template.xls"'; /* <--excel template to use*/
filename template dde 'excel|Leaflets!r6c1:r183c67';   /*put data in rows 3 to 183 in leaflets sheet*/


data LEAF.results; set LEAF.results;
file template ;
     put StartDate   EndDate   product_code   Description   Leaflet  Media  
         /*and the remaining 61 variables*/    
run;

DDE 程序运行并打开 excel 工作表,但数据在 excel 中的格式不正确,如下所示:

StartDate      EndDate      Product code   Description  Leaflet      Media
04 July 2013   07 July 2013    256554      BUTCHER         BEEF       1PK

如您所见,它似乎已将空格视为分隔符,但我不确定更改它的语法 - 可能还值得注意的是,我的实际数据集中有 67 个变量,所以我不想单独为它们提供信息和格式化。

另外,有没有办法将此数据集输出到我的 excel 模板中,然后将模板另存为我 c 驱动器上其他地方的不同文件名?

谢谢!

【问题讨论】:

    标签: sas export-to-excel dde


    【解决方案1】:

    在尝试了所有 DDE 选项后,我终于偶然发现了 LRECL。

    所以,

    options noxwait noxsync;
    x '"c:\Template.xls"'; /* <--excel template to use*/
    filename template dde 'excel|Leaflets!r6c1:r183c67' notab **LRECL=3000**;   /*put data in rows 6 to 183 in leaflets sheet*/
    
    
    data LEAF.results; set LEAF.results;
    file template ;
         put StartDate   EndDate   product_code   Description   Leaflet  Media  
             /*and the remaining 61 variables*/    
    run;
    

    我猜每个单元格中允许的默认字符长度太短,所以增加允许的长度意味着每个单元格不会被拆分为多个单元格?

    来源: http://support.sas.com/resources/papers/proceedings11/003-2011.pdf

    【讨论】:

      【解决方案2】:

      尝试将file template ;改为使用制表符分隔符,即file template dlm='09'x;;

      另外,在文件名中添加“notab”: 文件名模板 dde ​​'excel|Leaflets!r6c1:r183c67' notab;

      【讨论】:

      • 感谢,我之前尝试过,输出类似于不指定分隔符。我尝试了各种分隔符,但似乎都没有工作:/
      • 又添加了一项建议。
      • 你好。只是在上面尝试你的建议,它似乎没有任何区别。看起来一旦遇到缺失值,它就会开始新的一行。不知道为什么会发生这种情况,有没有办法告诉它将空值视为空白而不是行尾?谢谢!
      猜你喜欢
      • 1970-01-01
      • 2019-04-04
      • 1970-01-01
      • 2014-02-27
      • 1970-01-01
      • 2020-02-22
      • 1970-01-01
      • 1970-01-01
      • 2019-06-22
      相关资源
      最近更新 更多