Hello,
I am trying to create a simple program which would run a git status on a folder and do one of the following:
I got most of the way there, but the text gets written to the "path" column. I would like to write it outside of the table:
data _null_;
length path $255 status $10 staged $5;
array gitstats path status staged;
drop files n rc;
files = git_status("&folder");
file print ods=(variables=(path status staged));
if files GT 0 then
do;
put "The following changes are present in the directory, please check:";
do n = 1 to files;
do over gitstats;
rc = git_status_get(n, "&folder", vname(gitstats), gitstats);
end;
put _ods_;
end;
end;
else put "The folder is clean";
rc = git_status_free("&folder");
run;
How can I achieve this? Thanks for the help in advance.
Create a macro that will print a message to the result
%macro printmsg(msg);
data _msg;
message = "&msg";
run;
proc print data=_msg noobs;
run;
proc delete data=_msg;
run;
%mend;
change the code where you want to print to the result and use the DOSUBL function, it allows you to execute other steps while in a step like so:
data _null_;
length path $255 status $10 staged $5;
array gitstats path status staged;
drop files n rc;
files = git_status("&folder");
if files GT 0 then
do;
put "The following changes are present in the directory, please check:";
do n = 1 to files;
do over gitstats;
rc = git_status_get(n, "&folder", vname(gitstats), gitstats);
end;
file print ods=(variables=(path status staged));
put _ods_;
end;
end;
else do;
rc = dosubl('%printmsg(The folder is clean)');
end;
rc = git_status_free("&folder");
run;
Where 'outside of the table'?
Maybe you want a simple FILE PRINT; instead of File ODS.
However you would have to have a PUT statement for the variables when you want them in the output.
"Outside of the table" would be a row of text, akin to as if I opened an ods destination and ran ods text/proc odstext before running proc print. File print does work to some extent, but it produces a somewhat ugly monospace text in a frame.
Create a macro that will print a message to the result
%macro printmsg(msg);
data _msg;
message = "&msg";
run;
proc print data=_msg noobs;
run;
proc delete data=_msg;
run;
%mend;
change the code where you want to print to the result and use the DOSUBL function, it allows you to execute other steps while in a step like so:
data _null_;
length path $255 status $10 staged $5;
array gitstats path status staged;
drop files n rc;
files = git_status("&folder");
if files GT 0 then
do;
put "The following changes are present in the directory, please check:";
do n = 1 to files;
do over gitstats;
rc = git_status_get(n, "&folder", vname(gitstats), gitstats);
end;
file print ods=(variables=(path status staged));
put _ods_;
end;
end;
else do;
rc = dosubl('%printmsg(The folder is clean)');
end;
rc = git_status_free("&folder");
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.