楼主: zeugin
37709 34

[原创博文] SAS输出结果能导出到excel中吗? [推广有奖]

11
goodbody 发表于 2009-11-26 01:43:49 |只看作者 |坛友微信交流群
10# goodbody

/* Let's illustrate with an example.
Suppose the results we are interested in is the basic measurements of variable1 in data one*/
data one;
input variable1 variable2;
datalines;
1 2
4 5
7 8
;
run;
ods trace on;
proc univariate data=one;
var variable1;
run;
ods trace off;
/* We can find the names of all results in log window:
57   ods trace on;
58
59   proc univariate data=one;
60   var variable1;
61   run;
NOTE: Writing HTML Body file: sashtml3.htm
Output Added:
-------------
Name:       Moments
Label:      Moments
Template:   base.univariate.Moments
Path:       Univariate.variable1.Moments
-------------
Output Added:
-------------
Name:       BasicMeasures
Label:      Basic Measures of Location and Variability
Template:   base.univariate.Measures
Path:       Univariate.variable1.BasicMeasures
-------------
Output Added:
-------------
Name:       TestsForLocation
Label:      Tests For Location
Template:   base.univariate.Location
Path:       Univariate.variable1.TestsForLocation
-------------
Output Added:
-------------
Name:       Quantiles
Label:      Quantiles
Template:   base.univariate.Quantiles
Path:       Univariate.variable1.Quantiles
-------------
Output Added:
-------------
Name:       ExtremeObs
Label:      Extreme Observations
Template:   base.univariate.ExtObs
Path:       Univariate.variable1.ExtremeObs
-------------
NOTE: PROCEDURE UNIVARIATE used (Total process time):
      real time           0.37 seconds
      cpu time            0.09 seconds

62
63   ods trace off; */
*Suppose we want to export the BasicMeasures to Excel. After submitting the following codes, we will find SAS data b in work library*/
ods output BasicMeasures=b;
proc univariate data=one;
var variable1;
run;
/*
1. In the previous step, we have saved the result into SAS work library and in data b.
2. Let's save SAS data b into Excel file b, and put the Excel file forb on desktop.
   - Click on " File"on the upper left corner
   - Click on "Export Data"
   - Library: "WORK", Member: "B", and Click on "Next"
   - Select "Microsift Excel 97, 2000 or 2002 Workbook", and Click on "Next"
   - Click on "Browse"
   - Click on Desktop on the left, Filename:"forb", and click on "Save"
   - Click on "OK"
   - Assign a name to the exported table: "b", and click on "Finish"
   - On desktop, you will see Excel file forb which contains the SAS result you have selected. */

使用道具

12
第六根弦 发表于 2009-11-26 06:23:41 |只看作者 |坛友微信交流群
这个也是高难度

使用道具

13
zeugin 发表于 2009-11-26 13:06:07 |只看作者 |坛友微信交流群
hongbo2009 发表于 2009-11-25 22:51
SAS数据集导入到EXCEL中是可以的,可以直接用菜单操作,当然也可以编程实现。
两种方法都介绍一下行吗?

使用道具

14
lwien007 发表于 2009-11-26 15:21:51 |只看作者 |坛友微信交流群
可以先利用ods csvall输出为csv,然后自动转换成excel,比较麻烦。
  1. ods listing close;
  2. ods csvall body='d:\tmp.csv';
  3. proc means data=sashelp.class;
  4.         var height;
  5. run;
  6. ods csvall close;
  7. ods listing;
  8. filename dst dde'excel|system';
  9. data _null_;
  10.         rc=system('start excel');
  11. run;       
  12. data _null_;
  13.         x=sleep(5);
  14. run;
  15. data _null_;
  16.         file dst;
  17.         put '[open("d:\tmp.csv")]';
  18.         put '[save.as("d:\tmp.xls",1)]';
  19.         put '[file.close()]';
  20.         put '[quit()]';
  21. run;
复制代码

使用道具

15
hymen 发表于 2009-12-7 17:14:11 |只看作者 |坛友微信交流群
当然可以,非常方便

使用道具

16
helensun 发表于 2009-12-7 22:22:39 |只看作者 |坛友微信交流群
还有一简便的办法,先复制到WORD里,利用WORD的文字转换成表格的功能,转换为表格后再复制到Excel中

使用道具

17
houtiao 发表于 2009-12-8 09:24:08 |只看作者 |坛友微信交流群
用文本导入工具,很简单,我经常使用,大致介绍一下步骤:
1、选中所有需要存入excel的文本,复制;
2、新建excel,随便选中一个单元格,粘贴;
3、粘贴之后右下角会让你选择复制格式,选择“使用文本导入向导”
这样之后就是格式相对整齐的表格了
我是在sas9.2转入excel2007界面下操作的,别的版本没有尝试过。

使用道具

18
majacte 发表于 2009-12-8 23:25:48 |只看作者 |坛友微信交流群
huage 发表于 2009-11-25 22:17
hehe.. SAS is very powerful..
Search option 'ods tagsets.ExcelXP'  ,
which will show how SAS output to multiple-sheet excel workbook.

Hope it does help.
sas 还是有很强的功能的, 如huage所说 tagsets.excelxp 就是个不错的选择! 好好看看吧。
不过也有缺陷,比如字符型的数值(012278990)导入到excel 后 0 就没了,需要注意!

使用道具

19
zzh256 发表于 2009-12-9 02:59:57 |只看作者 |坛友微信交流群
Need study again

使用道具

20
kczhou23 发表于 2009-12-14 00:29:54 |只看作者 |坛友微信交流群
又学了一招。。。
一曲肝肠断
天涯何处觅知音

使用道具

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-4-27 12:32