By tangyaohua ( 九月 4, 2010 at 下午 3:01) · Filed under SAS, call symput, call symputx, sas
使用SAS macro的朋友都知道 call symput,这是个非常有用的东东,在data step和macro之间建立了一个接口。
大家用的最多,接触最早的是call symput,其实SAS还提供了它的一个兄弟,更强大的call symputx。
The four benefits of CALL SYMPUTX are:
1.) CALL SYMPUTX does not write a note to the SAS log when the second argument is numeric. CALL SYMPUT, however, writes a note to the log stating that numeric values were converted to character values.
2.) CALL SYMPUTX uses a field width of up to 32 characters when it converts a numeric second argument to a character value. CALL SYMPUT uses a field width of up to 12 characters.
3.) CALL SYMPUTX left-justifies both arguments and trims trailing blanks.CALL SYMPUT does not left-justify the arguments, and trims trailing blanks from the first argument only. Leading blanks in the value of name cause an error.
4.) CALL SYMPUTX enables you to specify the symbol table in which to store the macro variable, whereas CALL SYMPUT does not. This is accomplished by an optional third argument to the SYMPUTX function.
Permalink
By tangyaohua ( 九月 3, 2010 at 上午 10:51) · Filed under SAS
有时候哪,excel可能有点小问题,SAS无法直接读取。或者为了方便想直接通过SAS对excel进行修改什么的,就可以用到SAS提供的DDE技术(动态数据编辑,好像是这样翻译)。
/* invoke Excel and open new workbook */
Options noxwait noxsync;
x '"c:\program files\microsoft office\office11\excel.exe"';
Data _null_;
rc = sleep(5);
Run;
/* save blank spreadsheet to desired location */
Filename ddecmd dde 'excel|system';
Data _null_;
file ddecmd;
put '[SAVE.AS("c:\mywork\testfile.xls")]';
Run;
/* define fileref using DDE access method */
Filename myfile dde 'excel|c:\mywork\[testfile.xls]sheet1!r1c1:r&rows.c3' notab;
/* write to Excel workbook */
Data _null_;
file myfile;
set work.sasdat;
if _n_=1 then put 'name1' '09'x 'name2' '09'x 'name3';
put var1 ‘09’x var2 ‘09’x var3;
Run;
/* save workbook and quit Excel */
Filename ddecmd dde 'excel|system';
Data _null_;
file ddecmd;
put '[SAVE()]';
put '[QUIT()]';
Run;
这是最简单的对excel写操作。
DDE,是通过SAS与office|excel通信,然后将VB语法发送到office|excel,excel再独立完成读写操作。因而在SAS DDE中基本上可以像直接在excel中建立表格一样任意的修改数据、格式、颜色、字体什么的。而通过SAS macro技术可以使该过程批量化。
Permalink
Trackbacks / Pingbacks (4)
By tangyaohua ( 九月 2, 2010 at 上午 4:39) · Filed under SAS
SAS 可以读取的数据格式很多,但是对PDF,目前基本没支持。
在SAS的官方网站上,可以看到直接用infile语句读取PDF。如下:
data a;
infile "test.pdf";
length line $32000;
input line $char.;
run;
前提是,读取的PDF要是无压缩的(在ods pdf中 compress=no 选项)。
但是这样的读取哪,不是很理想,会遗漏部分信息。
在特定场合有些解决方式。比如想将SAS生成的pdf再读进来而且保证读取正确的话,可以使用如下代码生成tmp文件。
ods ps file=“test.tmp”;
然后再将tmp文件读进来。
Permalink