data bat;
do i=1 to 3;
com2="rem@echo off";
com="call nmgo" || compress("TEST"||i);
com1="call nmgo" || compress("TEST"||i) ||COMPRESS(".CTL -MAXLIM=3"||"");
output;
end;
run;
data _null_;
set bat;
file '/folders/myfolders/BOOTSTRAP_PED/BATFILEPREP/booti.bat';
put @1 com2 ;
put @2 com1;
run;
I have the attached code which works for what I want to do. However for the put statement I need to limit the rem@echo off to the first line of booti. What I have is this with rem@echo off in every other line:
rem@echo off CALL NMGO TEST1.CTL -MAXLIM=3 rem@echo off CALL NMGO TEST2.CTL -MAXLIM=3
but what I want is this for the rem@echo off to appear in only line 1:
rem@echo off CALL NMGO TEST1.CTL -MAXLIM=3 CALL NMGO TEST2.CTL -MAXLIM=3
If I understand what you want try
data _null_; set bat; file '/folders/myfolders/BOOTSTRAP_PED/BATFILEPREP/booti.bat'; If _n_ = 1 then put @1 com2 ; put @2 com1; run;
_n_ is an automatic variable that SAS increments at each "loop" through the data step. In this case it is, in effect, the "line read count".
So test that variable and only create the output the first time.
Unless you need that BAT data set elsewhere this could be done with
data _null_; file 'your file'; put @1 "rem@echo off"; do i=1 to 3; com="call nmgo" || compress("TEST"||i); com1="call nmgo" || compress("TEST"||i) ||COMPRESS(".CTL -MAXLIM=3"||""); put @2 com1; end; run;
You can test the automatic iteration counter, _N_, to know when you are on the first iteration of the data step.
Do you want the space after NMGO that appears in the example output or not?
data bat;
com2="rem@echo off";
do i=1 to 3;
com ='call nmgo' || cats("TEST",i);
com1='CALL NMGO ' || cats("TEST",i,'.CTL -MAXLIM=3);
output;
end;
run;
data _null_;
set bat;
file '/folders/myfolders/BOOTSTRAP_PED/BATFILEPREP/booti.bat';
if _n_=1 then put com2 ;
put @2 com1;
run;
Please post log entries in a code box. By now you should have realized that the message windows reformat the text and make the diagnostic characters that SAS supplies appear in the wrong location as well as sometimes inserting extra newline characters.
You are missing at least one closing quote mark in this line:
78 com1='call NMGO' || cats ("TEST",i,'.CTL -MAXLIM=3);
If I understand what you want try
data _null_; set bat; file '/folders/myfolders/BOOTSTRAP_PED/BATFILEPREP/booti.bat'; If _n_ = 1 then put @1 com2 ; put @2 com1; run;
_n_ is an automatic variable that SAS increments at each "loop" through the data step. In this case it is, in effect, the "line read count".
So test that variable and only create the output the first time.
Unless you need that BAT data set elsewhere this could be done with
data _null_; file 'your file'; put @1 "rem@echo off"; do i=1 to 3; com="call nmgo" || compress("TEST"||i); com1="call nmgo" || compress("TEST"||i) ||COMPRESS(".CTL -MAXLIM=3"||""); put @2 com1; end; 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.