Hi there,
I am trying to create a text file using user written code.
What I need to do is have a line at the top of the text file up to 100 characters.
Then I need to output my main data which could consist of a few thousand rows, which I am using the below code for.
PROC PRINT DATA=TCMPROC.TEST;
RUN;
PROC EXPORT DATA=TCMPROC.TEST
OUTFILE="\\C:\invoice_names.txt"
DBMS=TAB REPLACE;
PUTNAMES=YES;
RUN;
PROC PRINT;
RUN;
Then at the end of the file I need another line of data around 100 characters long to finish the text file.
How would I go about merging a unique header and footer record around the main data that I have by building on the code above?
Thanks,
Aidan
Hey,
If i understood correctly, you want to ass header and footer to your file.
You can use the FILE and put statement to write the header in the file and you can use the below code to write to the file.
But you need to remove the REPLACE option, as that would delete your file(and the header too).
Once the file is exported through proc export, you can open the file again and using option- MOD( its opens the file and append contents to the end of the file), See an example below:
DATA _null_;
file out mod;
put "------your footer here ----";
run;
Hey,
If i understood correctly, you want to ass header and footer to your file.
You can use the FILE and put statement to write the header in the file and you can use the below code to write to the file.
But you need to remove the REPLACE option, as that would delete your file(and the header too).
Once the file is exported through proc export, you can open the file again and using option- MOD( its opens the file and append contents to the end of the file), See an example below:
DATA _null_;
file out mod;
put "------your footer here ----";
run;
I believe your code should be:
DATA _null_;
file out mod;
put "------your footer here ----";
stop;
run;
Thanks, you are right.
It's good practice with DIS to avoid user written code as far as possible. I totally understand that this is not always feasable - but we can at least try.
What you could do is to have a pre-process implemented as user written code or as user transformation if you need this more than once and only write the header, then use a normal File Writer and add 'mod' under options so that the additional output gets appended to the external file.
In my working example I'm using the following code in the User Written transformation (Code generation mode: User written body):
data _null_;
file "&_OUTPUT";
put "--- my header line here ----";
run;
And then in the File Writer:
Which creates the following output:
--- my header line here ---- "Alfred","M","14","69","112.5" "Alice","F","13","56.5","84" "Barbara","F","13","65.3","98"
.....
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.