Good afternoon.
I am attempting to execute SAS code using a return value from a macro. I need to check to see if a user has flipped a switch from NO to YES and if YES then execute the code which will document tables contained in the code. The complicating issue is I'm attempting to "bracket" the code using proc scaproc. That means the proc must run at the beginning and the reporting documentation must run after the code. Also, after the reporting documentation a process runs that reads and parses out the particular data I want from the resulting proc scaproc text file. If the flag remains as NO the code should simply run without creating the text file or running the proc scaproc.
Changing the flag to YES (and attempting to invoke proc scaproc) doesn't seem to have any effect and I suspect including proc scaproc in its own macro(s) doesn't allow it to consider the code between the macros.
I know there are probably better ways to do this and I certainly look forward to hearing what people have to say.
%let document_flag = 'YES';
%macro document_table1;
%if document_flag = 'YES' %then %do;
proc scaproc;
record '<<path to create the text file.txt'>>;
run;
%end;
%mend;
%document_table1;
<<SAS Code and ODS Excel creation>>
%macro document_table2;
%if document_flag = 'YES' %then %do;
proc scaproc;
write;
run;
filename sca_rec ' <<path back to the initial text file>>;
data myinfo;
infile sca_rec truncover;
input @1 scaline $256.;
length type myinfo $100;
keep type myinfo;
retain prxifile prxofile prxidata prxodata prxoother;
if _n_ = 1 then do;
prxifile = prxparse("!\bJOBSPLIT: FILE INPUT (\b.*\b) \*/!");
prxofile = prxparse("!\bJOBSPLIT: FILE OUTPUT (\b.*\b) \*/!");
prxidata = prxparse("!\bJOBSPLIT: DATASET INPUT (\b.*\b) \*/!");
prxodata = prxparse("!\bJOBSPLIT: DATASET OUTPUT (\b.*\b) \*/!");
end;
if prxmatch (prxifile,scaline) > 0 then do;
myinfo = prxposn(prxifile,1,scaline);
type = 'Input File';
output myinfo;
end;
else if prxmatch (prxofile,scaline) > 0 then do;
myinfo = prxposn(prxofile,1,scaline);
type = 'Output File';
output myinfo;
end;
if prxmatch (prxidata,scaline) > 0 then do;
myinfo = prxposn(prxidata,1,scaline);
type = 'Input Dataset';
output myinfo;
end;
else if prxmatch (prxodata,scaline) > 0 then do;
myinfo = prxposn(prxodata,1,scaline);
type = 'Output Dataset';
output myinfo;
end;
run;
%end;
%mend;
%document_table2;
I have modified the first dozen or so lines to fix the problem. You need ampersands to make use of macro variables. And other minor changes as well.
%let document_flag = YES;
%macro document_table1;
%if &document_flag = YES %then %do;
proc scaproc;
record '<<path to create the text file.txt>>';
run;
%end;
%mend;
%document_table1;
%macro document_table2;
%if &document_flag = YES %then %do;
I have modified the first dozen or so lines to fix the problem. You need ampersands to make use of macro variables. And other minor changes as well.
%let document_flag = YES;
%macro document_table1;
%if &document_flag = YES %then %do;
proc scaproc;
record '<<path to create the text file.txt>>';
run;
%end;
%mend;
%document_table1;
%macro document_table2;
%if &document_flag = YES %then %do;
Thank you for taking the time and lending your expertise. I appreciate it very much.
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: