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

I am trying to automate a process that involves receiving several text files with dates in the filename (AAYYYYMMDD.TXT format).  I am attempting to iteratively:

1. Read the file into SAS for processing

2. Archive the file in a ZIPX archive

3. Delete or move the file from the working directory so that it is not processed again.

 

The filename zip method is only documented to read the text file into a data step and write sas datasets to a zip archive.  I can not find any documentation on writing text files to a zip archive.

 

I also attempted to use the ODS package method, but it seems to overwrite existing files in the archive when I access the package.  I need to be able to append new text files as they are processed and retain any exisitng files in the ZIP archive.  I will keep testing veriations on these methods, but any assistance would be appreciated.

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

@Jim_Cooper_hmsa

Without X command you'll have to read the data into SAS before writing it to a zip file which is not an ideal situation as this could alter your data (i.e. change the end-of-line indicator from CR to CRLF).

 

If such changes are acceptable (or controllable) then below code sample could show you the way.

/* create sample text file */
proc export 
  data=sashelp.class 
  dbms=csv 
  outfile="c:\temp\testtext.csv" 
  replace;
run;quit;


/* create and add members to zip archive */
filename foo ZIP 'c:\temp\testzip.zip' lrecl=1000000;

data _null_;
  infile "c:\temp\testtext.csv";
  file foo(test3.csv);
  input;
  put _infile_;
run;

data _null_;
  infile "c:\temp\testtext.csv";
  file foo(test4.csv);
  input;
  put _infile_;
run;

 

View solution in original post

4 REPLIES 4
Reeza
Super User

Do you have x command enabled? 

Honeslty this is easier to accomplish via line commands. 

Jim_Cooper_hmsa
Obsidian | Level 7

Reeza,

 

Unfortunately, no.  Our environment is a client server configuration and the security protocols don't allow the business users to run the command line on production servers. ODS package and FILENAME ZIP seem to be enabled, but not the X command. That was my first thought as well having built SAS projects in the past.

 

Patrick
Opal | Level 21

@Jim_Cooper_hmsa

Without X command you'll have to read the data into SAS before writing it to a zip file which is not an ideal situation as this could alter your data (i.e. change the end-of-line indicator from CR to CRLF).

 

If such changes are acceptable (or controllable) then below code sample could show you the way.

/* create sample text file */
proc export 
  data=sashelp.class 
  dbms=csv 
  outfile="c:\temp\testtext.csv" 
  replace;
run;quit;


/* create and add members to zip archive */
filename foo ZIP 'c:\temp\testzip.zip' lrecl=1000000;

data _null_;
  infile "c:\temp\testtext.csv";
  file foo(test3.csv);
  input;
  put _infile_;
run;

data _null_;
  infile "c:\temp\testtext.csv";
  file foo(test4.csv);
  input;
  put _infile_;
run;

 

Jim_Cooper_hmsa
Obsidian | Level 7
Patrick,
I was hoping to avoid converting the data for the reason that you had identified. However, Your solution is acceptable.
Thanks

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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
  • 4 replies
  • 1732 views
  • 0 likes
  • 3 in conversation