1. 程式人生 > 實用技巧 >SAS資料集操作-ODS輸出

SAS資料集操作-ODS輸出

  SAS可以輸出成HTML或PDF,這是通過使用SAS中提供的ODS語句來完成的。ODS代表輸出傳遞系統,它主要用於格式化SAS程式的輸出資料到好的報告,支援將多個PROC語句的結果合併到一個檔案中。

基本語法:

ODS outputtype
PATH pathname
FILE = filename and path
STYLE = stylename
;
PROC some proc
;
ODS outputtype CLOSE;

引數描述:

  • PATH表示在HTML輸出的情況下使用的路徑,其他型別的輸出,檔名中包含路徑;
  • STYLE表示SAS環境中提供的內建樣式之一。

1.建立HTML輸出

ODS HTML 
    PATH='/folders/myfolders/sasuser.v94/TutorialsPoint/'
    FILE='CARS2.html'
    STYLE=EGDefault;
proc SQL;
select make, model, invoice 
from sashelp.cars
where make in ('Audi','BMW')
and type = 'Sports'
;
quit;

proc SQL;
select make,mean(horsepower)as meanhp
from sashelp.cars
where make in
('Audi','BMW') group by make; quit; ODS HTML CLOSE;

2.建立PDF輸出

ODS PDF 
    FILE='/folders/myfolders/sasuser.v94/TutorialsPoint/CARS2.pdf'
    STYLE=EGDefault;
proc SQL;
select make, model, invoice 
from sashelp.cars
where make in ('Audi','BMW')
and type = 'Sports'
;
quit;

proc SQL;
select make,mean(horsepower)as
meanhp from sashelp.cars where make in ('Audi','BMW') group by make; quit; ODS PDF CLOSE;

3.建立RTF輸出

RTF是Rich Text Format的縮寫,意即多文字格式。這是一種類似DOC格式(Word文件)的檔案,有很好的相容性,使用Windows“附件”中的“寫字板”就能開啟並進行編輯。

ODS RTF 
FILE='/folders/myfolders/sasuser.v94/TutorialsPoint/CARS.rtf'
STYLE=EGDefault;
proc SQL;
select make, model, invoice 
from sashelp.cars
where make in ('Audi','BMW')
and type = 'Sports'
;
quit;

proc SQL;
select make,mean(horsepower)as meanhp
from sashelp.cars
where make in ('Audi','BMW')
group by make;
quit;

ODS rtf CLOSE;