I have to create some specialized reporting. Traditionally, when using SAS EG or SAS Desktop, this would have been done
using a "filename statement" . For example "Filename rptout ' C:\myfolder\myreport.txt";
data _null_;
file rptout;
set rptdata;
put @15 'Some Report Title';/
put @01 @ detail_ln;/
run;
filename rptout clear;
SAS DI is saying that one must use the "File Writer Transformation" which seems overly complex to me. What is the best way to
write to a text file in SAS DI" Is using the "File Writer Transformation" the bes way to go? Please advise and Thank you very much
in advance.
Hi @dphilip01
It is not difficult to do it in DI Studio, as long as you forget about the file writer and utilize the not-so-well-known feature that a file can be connected to a user written code transformation as output, if the default output work table is deleted.
DI Studio works with metadata objects, some of them representing physical objects, like libraries, permanent tables, deployed jobs and external files, while other only exist as metadata used in generating job code etc.
Any sort of SAS code can be written and executed in DI Studio, and the code can contain references to physical things in libname and filename statements etc, but they are "invisible". They do not appear in the inventory pane, and they cannot be traced, i.e. they do appear in an impact analysis. So in the long run it is a good idea to register these objects in metadata.
In your case, I would recommend the following:
1. Create the output file physically as an empty file in a folder that is visible from the DI server context.
2. Register the file in DI Studio. It is a simple task:
3. Pull a User Written transformation (found under "Data") into your job and delete the work table on the right side of the transformation.
4. Pull the input table into your job and connect it to the transformation as input.
5. Pull the file into your job and connect it to the transformation as output.
Then you have all metadata registrations in place. Open the transformation properties, select the Code pane and write your code as shown in this example. Note that DI Studio supplies macro variables for _INPUT and _OUTPUT which can be used in the code, so the code is unaffected by changes in table- and file names.
Cut from the code pane. The macro assignments are supplied by the transformation, the data step is the userwritten code:
Please ignore the two small blue circles, they came without my knowing why...
The file format and implicitly generating SAS code, is specified in the External File object.
That said, the File Writer transforamtion is unfortenately not a transformation you want to refer to when bragging about DI Studio.
If that transformation is not sufficient for your needs, you can always generate the file using User Written, or even a User Written Transformation.
Not sure how you define a "report", but usually DI Studio is not used as a report genration tool, it's targeted for ETL purposes.
Hi @dphilip01
It is not difficult to do it in DI Studio, as long as you forget about the file writer and utilize the not-so-well-known feature that a file can be connected to a user written code transformation as output, if the default output work table is deleted.
DI Studio works with metadata objects, some of them representing physical objects, like libraries, permanent tables, deployed jobs and external files, while other only exist as metadata used in generating job code etc.
Any sort of SAS code can be written and executed in DI Studio, and the code can contain references to physical things in libname and filename statements etc, but they are "invisible". They do not appear in the inventory pane, and they cannot be traced, i.e. they do appear in an impact analysis. So in the long run it is a good idea to register these objects in metadata.
In your case, I would recommend the following:
1. Create the output file physically as an empty file in a folder that is visible from the DI server context.
2. Register the file in DI Studio. It is a simple task:
3. Pull a User Written transformation (found under "Data") into your job and delete the work table on the right side of the transformation.
4. Pull the input table into your job and connect it to the transformation as input.
5. Pull the file into your job and connect it to the transformation as output.
Then you have all metadata registrations in place. Open the transformation properties, select the Code pane and write your code as shown in this example. Note that DI Studio supplies macro variables for _INPUT and _OUTPUT which can be used in the code, so the code is unaffected by changes in table- and file names.
Cut from the code pane. The macro assignments are supplied by the transformation, the data step is the userwritten code:
Please ignore the two small blue circles, they came without my knowing why...
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.
Ready to level-up your skills? Choose your own adventure.