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

Hello,

I am trying to create a simple program which would run a git status on a folder and do one of the following:

  • if there is nothing to commit, write a line to the result window stating this
  • if there are changes, write that and show what needs to be committed

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.

1 ACCEPTED SOLUTION

Accepted Solutions
BrunoMueller
SAS Super FREQ

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;

View solution in original post

3 REPLIES 3
ballardw
Super User

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.

js5
Pyrite | Level 9 js5
Pyrite | Level 9

"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.

BrunoMueller
SAS Super FREQ

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;
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1170 views
  • 0 likes
  • 3 in conversation