- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
问题陈述:
我无法使用 SAS 从 PDF 文件中读取数据。
什么效果好:
我可以从网站下载 PDF 并保存。
不工作(需要帮助):
我无法使用 SAS 从 PDF 文件中读取数据。预计源内容结构将始终保持不变。预期输出作为 jpg 图像附加。
如果有人知道并帮助我如何使用 SAS 程序解决这种情况,那将是一次很好的学习和帮助。
我试过这样的事情:
/*Proxy address*/
%let proxy_host=xxx.com;
%let port=123;
/*Output location*/
filename output "/desktop/Response.pdf";
/*Download the source file and save it in the desired location*/
proc http
url="https://cdn.nar.realtor/sites/default/files/documents/ehs-10-2020-overview-2020-11-19_0.pdf"
method="get"
proxyhost="&proxy_host."
proxyport=&port
out=output;
run;
%let lineSize = 2000;
data base;
format text_line $&lineSize..;
infile output lrecl=&lineSize;
input text_line $;
run;
DATA _NULL_ ;
X "PS2ASCII /desktop/Response.pdf
/desktop/flatfile.txt";
RUN;
最佳答案
您可以使用 Apache PDFBox®库,它是一个用于处理 PDF 文档的开源 Java 工具。可以从 SAS Proc GROOVY
中使用该库使用 Java 代码从 PDF 文档中去除文本及其在页面上的位置。
例子:
您将不得不编写更多代码才能从剥离的文本中创建数据集。
filename overview "overview.pdf";
filename ov_text "overview.txt";
* download a pdf document;
proc http
url="https://cdn.nar.realtor/sites/default/files/documents/ehs-10-2020-overview-2020-11-19_0.pdf"
method="get"
/*proxyhost="&proxy_host." */
/*proxyport=&port */
out=overview;
run;
* download the Apache PDFBox library (a .jar file);
filename jar 'pdfbox.jar';
%if %sysfunc(FEXIST(jar)) ne 1 %then %do;
proc http
url='https://www.apache.org/dyn/closer.lua?filename=pdfbox/2.0.21/pdfbox-app-2.0.21.jar&action=download'
out=jar;
run;
%end;
* Use GROOVY to read the PDF, strip out the text and position, and write that
* parse to a text file which SAS can read;
proc groovy classpath="pdfbox.jar";
submit
"%sysfunc(pathname(overview))" /* the input, a pdf file */
"%sysfunc(pathname(ov_text))" /* the output, a text file */
;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.text.PDFTextStripper;
import org.apache.pdfbox.text.TextPosition;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.util.ArrayList;
import java.util.List;
import java.io.FileWriter;
import java.io.PrintWriter;
public class GetLinesFromPDF extends PDFTextStripper {
static List<String> lines = new ArrayList<String>();
public GetLinesFromPDF() throws IOException {
}
/**
* @throws IOException If there is an error parsing the document.
*/
public static void main( String[] args ) throws IOException {
PDDocument document = null;
PrintWriter out = null;
String inPdf = args[0];
String outTxt = args[1];
try {
document = PDDocument.load( new File(inPdf) );
PDFTextStripper stripper = new GetLinesFromPDF();
stripper.setSortByPosition( true );
stripper.setStartPage( 0 );
stripper.setEndPage( document.getNumberOfPages() );
Writer dummy = new OutputStreamWriter(new ByteArrayOutputStream());
stripper.writeText(document, dummy);
out = new PrintWriter(new FileWriter(outTxt));
// print lines to text file
for(String line:lines){
out.println(line);
}
}
finally {
if( document != null ) {
document.close();
}
if( out != null ) {
out.close();
}
}
}
/**
* Override the default functionality of PDFTextStripper.writeString()
*/
@Override
protected void writeString(String str, List<TextPosition> textPositions) throws IOException {
String places = "";
for(TextPosition tp:textPositions){
places += "(" + tp.getX() + "," + tp.getY() + ") ";
}
lines.add(str + " found @ " + places);
}
}
endsubmit;
quit;
* preview the stripped text that was saved;
data _null_;
infile ov_text;
input;
putlog _infile_;
run;
/*
* additional SAS code will be needed to input the text as data
* and construct a data set that matches the original tabular content layout
*/
关于sas - 如何使用 SAS 程序从 PDF 中读取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65241570/
有没有办法从 .sas 文件中打开 SAS 数据集进行查看(即在“ViewTable”窗口中)? 最佳答案 我认为这会做你想做的: dm log "vt sashelp.air"; 只需更改 "sas
如何在 SAS 程序中将 sas 数据表 (sas7bdat) 设置为只读? — 即使在 session 之间,该表也必须保持只读状态,尤其是当另一个用户注册该库并尝试写入数据集时。一旦创建了这些表,
如何将 mmddyy 变量转换为 date9 变量?例如,假设我们有以下内容: x = 05/10/2011 我希望 x 的形式为 10May2011。所以我做了以下事情: xnew =
我正在使用以下代码将文本文件导入 SAS: proc import datafile="C:\Users\Desktop\data.txt" out=Indivs dbms=dlm replace;
您好,我有兴趣为我在 SAS 中生成的数据制作一些稍微复杂的自定义格式。我需要它是数字类型。 格式 1 0="-" >0="%" %" 即 0 >>>>>>> - .74 >>>>> 74% -.65
我正在尝试弄清楚如何读取文本文件 (300mb) 中以逗号分隔但数据位于一行中的数据。 数据看起来像这样: a,b,c,d,e,f,g,h,i,j,k,l,m,false,false,true,1,3
我想将 SAS 数据集从 SAS 导出到 FTP。我可以使用以下命令导出 csv 文件(或 txt 文件): %macro export_to_ftp(dsn= ,outfile_name= ); F
这个问题在 SAS forum 上讨论过,与会者最终同意不同意。 问题很简单:SAS 在编译时为所有变量分配一个缺失值UNLESS一个变量出现在sum 语句中(在这种情况下,SAS 在编译时分配了一个
众所周知,SAS需要特别注意句子中的引号。 例如 %let quoted="I'd like to"; data temp; set temp; quoted=""ed"; r
我对 SAS 完全陌生,我很绝望。 所以,我的代码是: DATA abc; INPUT AA BB CC DD EE; CARDS; ; RUN; PROC PRINT DATA = abc; T
我在使用如下所示的数据集时遇到问题。它是不同位置/周的库存计数: data have; input itm location $ week inv; cards; 3 x 1 30 3 x 2
我们需要确定我们现在使用的是什么类型的 SAS(pc SAS 或服务器 SAS)。有什么方法可以找出我们使用的是什么 SAS,是指 PC SAS 还是 SAS Server? 最佳答案 使用“proc
假设我有一个包含 n 行和 p 列的数据集,这样数据集中的每个条目都包含一个实数。我正在寻找一种方法来对每行中的 p 列进行排名。这个排名的输出应该是一个长度 - p 的排名向量,它说明了关系。 所以
我正在尝试打印一个带分隔符的文件,而不必指定所有列。我可以接近,但数字列总是被引用: DATA _NULL_; SET SASHELP.CARS (obs = 5 keep = Make Mode
SAS 软件可以成功读取的最大文件大小是多少。(不考虑硬件限制) 提前致谢。 最佳答案 引用最近播放的电视广告,答案是“无限加 1”。 SAS 在读取操作期间对文件的大小没有任何限制,尽管您可能会遇到
我有一个包含变量 y、x1 和 x2 的数据集。我想找到适合模型的方程式: y = k1*x1c1 + k2 *x2c2 通过找到 k1、c1、k2 和 c2。我如何在 SAS 中执行此操作?具体来说
SAS中是否有用于定义数组中字母序列的简写? 许多语言都具有轻松执行此操作的机制,我想SAS也是如此,尽管我找不到它的引用。 例如,在R中,我可以做 > x x [1] "a" "b" "c" "d
我有两个 SAS 数据集。第一个相对较小,包含唯一的日期和相应的 ID: date dateID 1jan90 10 2jan90 15 3jan90 20 ... 第二个
就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引起辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the he
我有一个主要是数值的变量,但是偶尔会有一个字符偷偷进入。因此,变量在 SAS 中存储为字符。我希望能够确定此字符变量中的各个值是否为数字。在知道哪些值是数字哪些是字符后,我想创建一个新的(数字)变量,
我是一名优秀的程序员,十分优秀!