Hello
I am trying to create a bat file that will put all of the text files that exist in my folder. These text files are required to generate define.xml for study tabulation data. Here's the code I used:
filename dotbat "make_define.bat";
data _null_;
file dotbat notitles;
drive = substr("&path",1,2);
put @1 drive;
put @1 "cd &path";
put @1 "type define_header.txt valuelist.txt whereclause.txt itemgroupdef.txt itemdef.txt itemdef_value.txt codelist.txt compmethod.txt comments.txt leaves.txt" @@;
put " closeit.txt > define.xml " ;
put @1 "exit";
run;
x "make_define";
When I ran the code, it creates a Window Batch File called make_define; however when I opened it in Notepad it basically repeats the code but no information about metadata it should have. I've never created a bat file before, but shouldn't it create a file that has all the information in the text files combined?
Any suggestion would be greatly appreciated!
What happens when you try running the generated TYPE command by hand?
Why are you using the OS to copy text files? Why not just use SAS code?
Something like this should work. Notice the use of MOD option on the FILE statement on all but the first data step.
filename myfiles "&path" ;
data _null_;
infile myfiles('define_header.txt');
file myfiles('define.xml') ;
input;
put _infile_;
run;
data _null_;
infile myfiles('valuelist.txt');
file myfiles('define.xml') MOD ;
input;
put _infile_;
run;
...
@Hanako wrote:
Hello
I am trying to create a bat file that will put all of the text files that exist in my folder. These text files are required to generate define.xml for study tabulation data. Here's the code I used:
filename dotbat "make_define.bat";
data _null_;
file dotbat notitles;
drive = substr("&path",1,2);
put @1 drive;
put @1 "cd &path";
put @1 "type define_header.txt valuelist.txt whereclause.txt itemgroupdef.txt itemdef.txt itemdef_value.txt codelist.txt compmethod.txt comments.txt leaves.txt" @@;
put " closeit.txt > define.xml " ;
put @1 "exit";
run;
x "make_define";
When I ran the code, it creates a Window Batch File called make_define; however when I opened it in Notepad it basically repeats the code but no information about metadata it should have. I've never created a bat file before, but shouldn't it create a file that has all the information in the text files combined?
Any suggestion would be greatly appreciated!
Without the contents of any of those text files mentioned the bold text above is not very clear. If the text files do not contain lines of text describing the "metadata" then the result wont' have it either. All that the TYPE command does is display the text content of a file.
I checked the text files created from the SAS code it does contain the metadata that make up a define.xml file. Text files were created from an excel spreadsheet (metadata specifications) and each text file contains the content that matches the corresponding tab in the spreadsheet. What I am trying to do is to combining all the text files generated which can be used as the define.xml portion of my metadata.
Use FILEVAR=, naked INPUT statement, and PUT _INFILE_.
See http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000146932.htm
Dummy code:
data _null_;
length fileloc myinfile $ 300;
input fileloc $ ; /* read instream data */
/* The INFILE statement closes the current file
and opens a new one if FILELOC changes value
when INFILE executes */
infile file-specification filevar=fileloc
filename=myinfile end=done;
file out;
/* DONE set to 1 when last input record read */
do while(not done);
/* Read all input records from the currently */
/* opened input file, write to ALLSALES */
input;
put _infile_;
end;
put 'Finished reading ' myinfile=;
datalines;
external-file-1
external-file-2
external-file-3
;
run;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.