Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
SAS将数据集导出为csv或excel,保留换行符_Csv_Sas_Export - Fatal编程技术网

SAS将数据集导出为csv或excel,保留换行符

SAS将数据集导出为csv或excel,保留换行符,csv,sas,export,Csv,Sas,Export,我试图将我的数据集从SAS导出到excel,无论是csv格式还是xls格式,但是当我这样做时,带换行符的列会弄乱我的excel。有没有办法将SAS数据集导出到excel,以保留换行符?我还需要显示标签而不是列名,数据集相当大,大约有150000行 这就是我所做的 proc export data=Final_w_label outfile='work/ExtractExcel.csv' dbms=csv label replace; run; quit; 提前感谢。请参阅文章底部的示例数据 创

我试图将我的数据集从SAS导出到excel,无论是csv格式还是xls格式,但是当我这样做时,带换行符的列会弄乱我的excel。有没有办法将SAS数据集导出到excel,以保留换行符?我还需要显示标签而不是列名,数据集相当大,大约有150000行

这就是我所做的

proc export data=Final_w_label
outfile='work/ExtractExcel.csv'
dbms=csv label replace;
run; quit;

提前感谢。

请参阅文章底部的示例数据

创建Excel可以轻松打开并显示嵌入换行符的导出的一种有效方法是使用XML

libname xmlout xmlv2 'c:\temp\want.xml';
data xmlout.want;
  set have;
run;
libname xmlout;
在Excel(365)do File/Open中,选择
want.xml
文件,然后在引发的辅助
打开xml
对话框中选择
作为xml表

其他方式

还有其他方法可以将SAS数据移动到Excel可以解析的表单中。Proc EXPORT将创建一个文本文件,在字符变量中嵌入回车符(Excel用于单元格内换行)

导出的问题是Excel无法使用其向导正确导入数据。可能有一个vbs解决方案用于读取导出,但这可能会带来更多麻烦

另一种导出形式是创建
.xlsx
文件的
dbms=excel

proc export dbms=excel data=have label replace file='c:\temp\want.xlsx';
run;
此导出可以通过Excel打开,并且所有列都是正确的。但是,在带有内嵌回车符的单元格中,数据值的初始视图表示形式似乎没有换行符。使用编辑模式进行进一步检查将显示嵌入的新行在那里,按Enter键(接受编辑)将使单元视图显示嵌入的新行。您不希望必须按预期对每个单元进行F2渲染

样本数据

data have (label="Lines within stanza are separated by newline character");
  attrib 
    id length=8 label='Identity'
    name length=$50 label='Poem name'
    auth length=$50 label='Author'
    stanza1-stanza20 length=$250;
  ;

  array stz stanza:;

  id + 1;
  section = 1;

  infile cards eof=last;

  do while (1=1);
    linenum + 1;
    input;
    select;
      when (_infile_ = '--') leave;
      when (linenum = 1) name = _infile_;
      when (linenum = 2) auth = _infile_;
      when (_infile_ = '') section + 1;
      otherwise stz(section) = catx('0d'x, stz(section), _infile_);
    end;
  end;

last:

  output;

  datalines4;
Trees
Joyce Kilmer
I think that I shall never see
A poem lovely as a tree.

A tree whose hungry mouth is prest
Against the earth’s sweet flowing breast;

A tree that looks at God all day,
And lifts her leafy arms to pray;

A tree that may in Summer wear
A nest of robins in her hair;

Upon whose bosom snow has lain;
Who intimately lives with rain.

Poems are made by fools like me,
But only God can make a tree.
--
;;;;
run;

带换行符的列是什么意思?如果需要Excel,请导出到Excel而不是CSV。CSV文件是一个文本文件,SAS几乎无法控制它如何解释事物
ODS EXCEL
是一个非常强大的选项。
data have (label="Lines within stanza are separated by newline character");
  attrib 
    id length=8 label='Identity'
    name length=$50 label='Poem name'
    auth length=$50 label='Author'
    stanza1-stanza20 length=$250;
  ;

  array stz stanza:;

  id + 1;
  section = 1;

  infile cards eof=last;

  do while (1=1);
    linenum + 1;
    input;
    select;
      when (_infile_ = '--') leave;
      when (linenum = 1) name = _infile_;
      when (linenum = 2) auth = _infile_;
      when (_infile_ = '') section + 1;
      otherwise stz(section) = catx('0d'x, stz(section), _infile_);
    end;
  end;

last:

  output;

  datalines4;
Trees
Joyce Kilmer
I think that I shall never see
A poem lovely as a tree.

A tree whose hungry mouth is prest
Against the earth’s sweet flowing breast;

A tree that looks at God all day,
And lifts her leafy arms to pray;

A tree that may in Summer wear
A nest of robins in her hair;

Upon whose bosom snow has lain;
Who intimately lives with rain.

Poems are made by fools like me,
But only God can make a tree.
--
;;;;
run;