Hello,
I am using the options mprint mlogic to check how my SAS code is working.
But It seems difficult to see if based on the if conditions if the sas code visit a part of the program and not the others.
Is there a way to do that ?
Example :
%let co eq ha;
%macro test;
data a;
set b;
if "&co" eq ha then
do;
end;
else
do;
end;
run;
%if &co eq ha %then
%do;
%end;
%mend test;
%test;
In the dataset portion of the code it seems difficult to see which part of the code are visited.
Is there a way to trace which part of the SAS code is read based on a condition.
Ancient is to add a Put or %Put At the location(s) of interest in the code;
make sure the description means something to you.
Possibly include one or more variables
%macro test; data a; set b; if "&co" eq ha then do; put "in data step &co block"; end; else do; put "in data step else block"; end; run; %if &co eq ha %then %do; %put In macro if &co equal ha block; %end; %mend test;
Ancient is to add a Put or %Put At the location(s) of interest in the code;
make sure the description means something to you.
Possibly include one or more variables
%macro test; data a; set b; if "&co" eq ha then do; put "in data step &co block"; end; else do; put "in data step else block"; end; run; %if &co eq ha %then %do; %put In macro if &co equal ha block; %end; %mend test;
Hi,
You can use the putlog statement which can be used to put text to the log indicating you are in a specific part of the program.
E.g.:
data want;
set sashelp.class;
if name eq: 'J' then
do;
putlog _n_ "condition was true";
end;
else
do;
putlog _n_ "condition was false";
end;
run;
In this case, the log shows:
1 condition was false 2 condition was false 3 condition was false 4 condition was false 5 condition was false 6 condition was true 7 condition was true 8 condition was true 9 condition was true 10 condition was true 11 condition was true 12 condition was true 13 condition was false 14 condition was false 15 condition was false 16 condition was false 17 condition was false 18 condition was false 19 condition was false NOTE: There were 19 observations read from the data set SASHELP.CLASS.
Obviously, you might only want one part of the if-then-else condition to have this as your log might get too big.
Alternatively, you might be able to use the SAS data step debugger, by isolating the data step code.
Thanks & kind regards,
Amir.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.