Last active
July 10, 2020 03:50
-
-
Save statgeek/264fe76bdccb6b137215 to your computer and use it in GitHub Desktop.
Using SAS to Append PDF files together
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
****************************************************************** | |
This requires Adobe Acrobat Professional | |
List files to append in order | |
******************************************************************; | |
Data Files2Append; | |
length file $256.; | |
file="C:\Test\Sample_out.PDF"; output; | |
file="C:\Test\Sample_out 2.PDF"; output; | |
run; | |
*Get number of files to process; | |
proc sql noprint; | |
select count(*) into :num_append from Files2Append; | |
quit; | |
%put Number of files to Append: &num_append; | |
Data Dim_Declare; | |
do i=1 to &num_append; | |
row=put(i, 2. -l); | |
Code=catt("Dim Doc", row); | |
output; | |
end; | |
do i=1 to &num_append; | |
row=put(i, 2. -l); | |
Code=catt("Set Doc", row, '=CreateObject("AcroExch.PDDoc")'); | |
output; | |
end; | |
keep Code; | |
run; | |
Data Append_Files; | |
length code $2000.; | |
set Files2Append; | |
row=put(_n_, 2. -r); | |
Code=cat(compress('file'|| row),compress(" = Doc"|| row), '.Open(', quote(trim(file)), ")"); | |
Keep Code; | |
run; | |
Data Stack_Files; | |
do i=2 to &num_append; | |
doc_id=compress("Doc"||put(i, 2. -l)); | |
doc_pages=compress(doc_id||".GetNumPages"); | |
Code=cat("Stack = Doc1.InsertPages(Doc1.GetNumPages - 1, ", doc_id, ", 0, ", doc_pages, " ,0 )"); | |
output; | |
end; | |
****************************************************************** | |
Change the final output file name/location here | |
******************************************************************; | |
Code=cat("SaveStack=Doc1.Save(1, ", quote("C:\Test\Stacked_Files.PDF"), ")"); output; | |
run; | |
*OUTPUT VBS CODE; | |
filename temp "C:\Test\Append_Files.vbs"; | |
DATA allcode; | |
set Dim_Declare Append_Files Stack_Files; | |
file temp; | |
put code; | |
RUN; | |
*RUN VBS PROGRAM; | |
%sysexec "C:\Test\Append_Files.vbs"; |
Author
statgeek
commented
Jul 15, 2019
via email
•
The code generates the vbs file. You need to change the list of files at the top but then SAS writes the vbs file in the last step and then executes it via the system command. That may or may not work for you, depends on if you have xcmd enabled.
Fareeza
…Sent from my iPhone
On Jul 15, 2019, at 8:18 AM, Ceperon ***@***.***> wrote:
Hello, can you provide the code for Append_Files.vbs. Thank you.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or mute the thread.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment