DATA Step, Macro, Functions and more

input and output files

Super Contributor
Posts: 713

input and output files

I have 15 sas scripts on unix box and i need to create a report showing the name of the sas script,all the input files and all the output files.
Posts: 9,365

Re: input and output files

When you say you have SAS "scripts" -- do you mean that you have Perl scripts or PHP scripts or Basic scripts that invoke SAS programs or do you mean that you have 15 .SAS programs????

If you are talking about SAS programs -- they are just ASCII text files. You could pipe a directory list to a file and then read that file of program names with a SAS program and/or a SAS macro program. If you were looking to read your text (.SAS) file, then you would search every program for references to DATA or SET or MERGE or INFILE. When you say you need to know the names of the output files, do you mean the datasets that are output by the programs or do you mean the ODS output???

There have been some user group papers written that talk about parsing SAS programs with another program. (look for the paper, entitled Meta Data + Files = Automated Status Reports)

You could also look at the SAS Code Analyzer (SCAPROC):

Frequent Contributor
Posts: 91

Re: input and output files

Posted in reply to Cynthia_sas

I read SAS programs as 1000 character text variables. I then can, as Cynthia suggests, use various search methods like a WHERE statement to find DATA STEPS and extract only those lines or mark the line number in the program to know the beginning and end of the DATA STEP.  Or I can do a character search of that first keyword in a DATASTEP like DATA nameofdatset; to extract "nameofdataset.". I can find what the line number is for the beginning of that DATA STEP. I generally create an (_n_) based variable to define the line numbers to match the text variable containing the SAS program where one line of code is one observation.

Trusted Advisor
Posts: 2,124

Re: input and output files

For full generality, you could write a unix script to get the names of the SAS scripts from the Unix box and then feed that to a macro to parse the script results and find the files.

With just 15 scripts, you could do it manually much faster than writing the code de novo.
Ask a Question
Discussion stats
  • 3 replies
  • 4 in conversation