BookmarkSubscribeRSS Feed
Hanako
Calcite | Level 5

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! 

 

5 REPLIES 5
Tom
Super User Tom
Super User

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;

...

 

 

ballardw
Super User

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

Hanako
Calcite | Level 5

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. 

Reeza
Super User
Did you try the code directly in the OS as a batch file and it produces the right results?
ScottBass
Rhodochrosite | Level 12

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;

Please post your question as a self-contained data step in the form of "have" (source) and "want" (desired results).
I won't contribute to your post if I can't cut-and-paste your syntactically correct code into SAS.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 1384 views
  • 0 likes
  • 5 in conversation