BookmarkSubscribeRSS Feed
Tiffanie
Calcite | Level 5

As part of our business, we need to save our SAS programs in PDF format with a header.

We would then like to be able to copy paste the program from the PDF to SAS and run it without having to modify it.

For this, the headers of the created PDFs are between "/* */" so that they are commented in the program and therefore do not interfere with its execution. However, this causes problems when this header falls in the middle of a data step, because comments in this format are not valid in datalines.

 

Do you have an idea / solution to either allow comments in a data step, or guarantee that the data steps are never on several PDF pages?

Indeed, the PDF is created automatically by the following code:

title j=l "/* header */";
ods pdf file="location" style=define_style;
filename sas "location.sas";
data _null_;
infile sas expandtabs;
input;
temp =_infile_;
file print ods=(template="PDF");
put _ods_;
run;
ods pdf close;

Thks for your response.

4 REPLIES 4
PaigeMiller
Diamond | Level 26

@Tiffanie wrote:

As part of our business, we need to save our SAS programs in PDF format with a header.

We would then like to be able to copy paste the program from the PDF to SAS and run it without having to modify it.

For this, the headers of the created PDFs are between "/* */" so that they are commented in the program and therefore do not interfere with its execution. However, this causes problems when this header falls in the middle of a data step, because comments in this format are not valid in datalines.

 

Do you have an idea / solution to either allow comments in a data step, or guarantee that the data steps are never on several PDF pages?


Comments cannot be in DATALINES and so the only suggestion I have is to put the comments before the DATALINES. This really has nothing to do with PDF at all.

--
Paige Miller
Kurt_Bremser
Super User

Code meant to be used should always be stored in simple text files (.sas).

The only times I put SAS codes in pdf files was for presentation papers, and there the code examples are usually short, and filtering out page breaks poses no great work for those copying the code.

Versioning software will also work with simple text only; such software will usually allow you to define a plugin for automatic export to pdf for display purposes.

ballardw
Super User

"Comments" in data lines really are not such. They are considered values to read. The way to place a "comment" in a datalines block is to place the text where the INPUT statement will not read it.

 

Data example;
  input x y;
datalines;
1 2
1 3
4 5   /* this is imitating a comment in data lines because Input is not reading it*/
;

 

Tom
Super User Tom
Super User

If the question is how to convert a text file that looks like:

/* Some title */
data class ;
  input Name $ Sex :$1. Age Height Weight;
cards;
Alfred M 14 69 112.5
Alice F 13 56.5 84
Barbara F 13 65.3 98
Carol F 14 62.8 102.5
Henry M 14 63.5 102.5
James M 12 57.3 83
Jane F 12 59.8 84.5
Janet F 15 62.5 112.5
Jeffrey M 13 62.5 84
/* Some title */
John M 12 59 99.5
Joyce F 11 51.3 50.5
Judy F 14 64.3 90
Louise F 12 56.3 77
Mary F 15 66.5 112
Philip M 16 72 150
Robert M 12 64.8 128
Ronald M 15 67 133
Thomas M 11 57.5 85
William M 15 66.5 112
;

Into

data class ;
  input Name $ Sex :$1. Age Height Weight;
cards;
Alfred M 14 69 112.5
Alice F 13 56.5 84
Barbara F 13 65.3 98
Carol F 14 62.8 102.5
Henry M 14 63.5 102.5
James M 12 57.3 83
Jane F 12 59.8 84.5
Janet F 15 62.5 112.5
Jeffrey M 13 62.5 84
John M 12 59 99.5
Joyce F 11 51.3 50.5
Judy F 14 64.3 90
Louise F 12 56.3 77
Mary F 15 66.5 112
Philip M 16 72 150
Robert M 12 64.8 128
Ronald M 15 67 133
Thomas M 11 57.5 85
William M 15 66.5 112
;

Then perhaps you just need to look for that TITLE line.

data _null_;
  infile 'file pulled form pdf.txt' ;
 file 'myprogram.sas';
 input;
  if _infile_= '/* Some title */' then delete;
  put _infile_;
run;

 

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1083 views
  • 1 like
  • 5 in conversation