Hi, I am trying to use filename _fout statement to output .sh file instead of proc export because I see that filename _fout can support permissions parameter. By Default, using proc export will not generate .sh file with executable permissions. Using filename _fout allows doing so.
%let default_dir=/sas/config/Lev1/AppData;
%let filename=test.sh;
%macro test();
data a;
attrib command length=$1000.;
%do j=1 %to &count;
command="cp &default_dir./&&filename&j. &sas_app_root./csv/";
output;
command="unzip &sas_app_root./csv/&&filename&j. -d &sas_app_root./csv/";
output;
command="rm -f &sas_app_root./csv/&&filename&j.";
output;
%end;
run;
%mend;
%test;
%macro output();
filename _fout "&default_dir./csv/csv_poc.sh" permission='A::u::rwx,A::g::r-x,A::o::---';
data _NULL_;
/* set WORK.shell_command; */
file _fout;
%do j=1 %to &count;
put bbb;
%end;
run;
filename _fout;
%mend;
%output;
I couldn't find a way to let filename function to take in value from work.a;
Also, it seems like it will not output bbb in the .sh file using my script.
What did I do wrong?
Did you have working code before you attempted this macro approach? If so, show us that code.
You do not show where the macro variable COUNT is assigned a value. So that is one likely problem point.
You do not appear to actually use data set A anywhere. Then your "Output" macro attempts to use a variable BBB that does not have a source to come from (no data set on a SET statement as shown) and your Work.A data set if created would only have one variable, Command, not BBB as attempted.
Any path used in a Filename statement should start at a drive (WINDOWS) or drive mount point, otherwise it is going to be treated as relative to the current operating directory and not pointing where you think it is.
What did your log look like when submitting this code.
Set: OPTIONS MPRINT; then run the macro and show us the LOG of the result to see the code you are actually generating.
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.