SAS使用技巧- 动态抓取外部URL的网友内容

类别:编程语言 点击:0 评论:0 推荐:

 

 使用之前先要注意一下SAS的版本,SAS8的话需要打补丁,并且好像SAS网站上没有直接的补丁,需注意了,9版当然就没有这问题了
 
 其实实现这已内容很简单,就是通过SAS的DATA STEP来实现
 
 首先:需做一个逻辑文件名引用到该URL地址
 然后通过DATA STEP都该文件名即可把内容读取出来
 代码如下:
  filename 引用名 url 'URL地址'   RECFM=v(读取格式,V表以文本格式读取) lrecl=N(每行最长的记录)  ;                                                                                                                                                                                                    
  data 表名;                                                                                                                                                                                                                                          
  file _webout;                                                                                                                                                                                                                                     
  infile 引用名 LINESIZE =N pad  ;                                                                                                                                                                                                                   
  length content  $32766. ;                                                                                                                                                                                                        
  input content $char32766.;                                                                                                                                                                                                                            
  run;                                                                                                                                                                                                                                                  

 即可实现抓取URL所指向的网页内容,但是很奇怪的是,联系运行上面代码会造成SAS崩溃,真是奇怪,后来把代码改成如下:

  filename 引用名 url 'URL地址'   RECFM=v(读取格式,V表以文本格式读取) lrecl=N(每行最长的记录)  ;                                                                                                                                                                                                    
  data 表名;                                                                                                                                                                                                                                          
  file _webout;                                                                                                                                                                                                                                     
  infile 引用名   length=len;                                                                                                                                                                                                                   
  length content  $32766. ;                                                                                                                                                                                                        
  input content $varying32766. len;                                                                                                                                                                                                                            
  run;                                                                                                                                                                                                                                                  
 
 竟然就不会造成SAS当掉,奇怪啊奇怪

本文地址:http://com.8s8s.com/it/it25120.htm