I have used SCAPROC to list particular variables in my code, but I can't seem to figure out a way to also list my macro arguments from the same code. An example of these arguments would be the report= and subject= in EXAMPLE 1. I can use the code from EXAMPLE 2 to
determine the table names used in the code and save it as a text file but I can't seem to be able to list the macro variables from EXAMPLE 1.
Can anyone point me in a potential direction?
EXAMPLE 1 %macro email_result; %if &syserr=0 or &syserr=4 %then %do; %dw_std_email(report="AUTO &report_name",subject="&subject_line", attach1="&file_path &file_name" content_type="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); %end; %mend; %email_result; EXAMPLE 2 %macro document_table2; %if &documentation_flag. = 'YES' %then %do; proc scaproc; write; run; filename sca_rec "&documentation.\&documentation_name..txt"; data myinfo; infile sca_rec truncover; input @1 scaline $256.; length library_name $20 table_name $25 data_type $5; keep library_name table_name data_type; retain prxfile prxidata; if _n_ = 1 then do; prxifile = prxparse("!\bJOBSPLIT: FILE INPUT SEQ (\b.*\b) \*/!"); prxidata = prxparse("!\bJOBSPLIT: DATASET INPUT (\b.*\b) \*/!"); end; if prxmatch (prxidata,scaline) > 0 then do; if scan(prxposn(prxidata,1,scaline), -1) = 'MULTI' OR scan(prxposn(prxidata,1,scaline), -1) = 'SEQ' then do; myinfo = scan(prxposn(prxidata,1,scaline), -1, ' '); library_name = scan(myinfo,1, '.'); table_name = scan(myinfo,2, '.'); data_type = scan(myinfo,3, '.'); end; else do; myinfo = scan(prxposn(prxidata,1,scaline), -1, ' '); library_name = scan(myinfo,1, '.'); table_name = scan(myinfo,2, '.'); data_type = scan(myinfo,3, '.'); end; end; if library_name ne ' '; run; proc export data = myinfo outfile = "&documentation.\&documentation_name..xls" dbms = xls replace; run; %end; %mend; %document_table2;
Not exactly answering your question but... One way to capture the SAS code macros generate is using option mfile which lets you route mprint output to an external file.
Hello,
I think the answer from @Patrick is exactly what you need.
Should you still want to use PROC SCAPROC, then why don't you have a RECORD statement?
I only see PROC SCAPROC with a WRITE statement.
You need (I think!) to specify a record file (like 'record.txt'
) and write information from the SAS Code Analyzer (SCA) to that file.
Like here:
SAS® 9.4 and SAS® Viya® 3.5 Programming Documentation
Base SAS Procedures Guide
SCAPROC Procedure
Example 1: Specifying a Record File
https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/proc/n189k80mdf3lbkn10rhifnic7zx8.htm
Not sure if the written file will contain what you want though (I have never used PROC SCAPROC myself 🙁).
BR, Koen
Good morning.
Yes, I do have the record file. I just didn't post it as I supposed it was not relevant to the question. Thanks for taking the time to reply and offering help.
From a look at the docs, I don't think you can get the macro arguments. The only feature I see relating to macro variables is you can get a record stating that a macro variable was created (SET) or referenced (GET). So when I run:
proc scaproc;
record 'Q:\junk\record.txt';
run;
%let q=1 ;
%macro foo(qqq=) ;
%put &=qqq ;
%mend foo ;
%foo(qqq=0)
proc scaproc;
write;
run;
I do get SYMBOL records for the creation of Q and QQQ, and the reference of QQQ:
/* JOBSPLIT: SYMBOL SET Q */ /* JOBSPLIT: SYMBOL SET QQQ */ /* JOBSPLIT: SYMBOL GET QQQ */
But that isn't giving you the value assigned to a macro variable, or the name of the macro invoked.
Hi @Jeff_DOC
Typically when starting PROC SCAPROC, you would specify the recording file along with some options
* Start recording info to a text file ;
proc scaproc ;
record "<FileName>" attr opentimes expandmacros ;
run ;
In order to capture your macro programs logic and parameters, ensure to have at least the following options in effect before starting the recording
options symbolgen mprint mprintnest msglevel=i ;
All the macro debugging information should be captured in the source code section with the recording output file.
Hope this helps,
Ahmed
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.