BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Jeff_DOC
Pyrite | Level 9

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;

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

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;
--
Paige Miller

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26

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;
--
Paige Miller
Jeff_DOC
Pyrite | Level 9

Thank you for taking the time and lending your expertise. I appreciate it very much.

 

 

Ready to join fellow brilliant minds for the SAS Hackathon?

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!
How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 757 views
  • 0 likes
  • 2 in conversation