SAS技术应用-以流的方式读取、写入文件

来源:互联网 发布:人工智能的挑战与机遇 编辑:程序博客网 时间:2024/06/07 18:56

length rec $256 crc $1 rc 8;                                                 
init:                                                                        
  submit continue;                                                           
filename h url "http://localhost/draft1.xls" recfm=f;                            
data crlibm.report_xls(compress=yes);                                               
infile h;                                                                    
input rec $char256.;
rpt_id=1;rownum=_n_;                                                        
run;                                                                         
  endsubmit;    

/*如果crlibm置于spde引擎之下,由于多线程读取的原因,不能保证rownum顺序获得*/
  submit continue;
proc sql;
create view v1 as
select * from crlibm.report_xls
where rpt_id=1
order by rownum;
  endsubmit;                                                            
                                                                             
  crc=appsrv_header('Content-type','application/vnd.ms-excel');              
  crc=appsrv_header('Content-disposition','attachment;filename=t.xls');      
/*IT下,由于data step中无法设定_webout的文件属性,导致xls流不能正确输出*/                                                                             
  fid=fopen('_webout','A',0,'B');                                            
  dsid=open('v1');                                                   
  do while(fetch(dsid)^=-1);                                                 
     rec=getvarc(dsid,1);                                                    
     rc=fput(fid,put(rec,$char256.));                                        
     rc=fwrite(fid);                                                         
  end;                                                                       
  dsid=close(dsid);                                                          
  fid=fclose(fid);                                                           
return;

 

原创粉丝点击