BookmarkSubscribeRSS Feed
jasbrn33
Fluorite | Level 6

I have a macro that creates a zip file to archive all datasets from ONE folder. I would also like to also include only a few datasets from a different folder into that same zip file, if possible?

I'm using an already built out macro call 'zip(path, zip name, ziplock);' which will create a zip file from a folder. How can I add other datasets from another folder in that zip file without moving the datasets into that folder manually after.

The macro parameters are defined below:
path = file path of directory to be zipped
zip name = name of new zip file
ziplock = location of new zip file

I would like to zip an entire folder AND a few datasets from another folder

3 REPLIES 3
himself
Quartz | Level 8

Would say create a global macro of the path, such that the macro variable "&path" will be looping in the different paths that you will have created in the global macro.

ballardw
Super User

Do you have rules for finding the names of "the different folders" and the associated sets? Or is this an ad hoc thing where the names/locations change in a nearly random fashion?

 

If ad hoc I would leave your macro alone and use operation system tools to add the files to the created Zip file.

If you can write code given some values then make the names of those parameters keyword parameters that you test in the macro for if they are populated and if so run the code to add the desired sets to the Zip file.

 

Conceptual code

%Macro zip(path=, zipname=, ziplock=, altfiles=N,altfolder=, altsetlist);
<existing code to write to the zip file>
  
  %if &altfiles=Y %then %do;
   <use the altfolder info >
   <combine the altsetlist info to get lib.dataset constructs>
   <add the constructs to Zip>
 %end;
<finish the process>
%mend;

If you haven't used keyword parameters, i.e. the name followed by = it is likely time to learn. Keywords do not require parameters to appear in order and can have defaults that you override.

The above uses a parameter Altkey=N (default of N) that doesn't activate the the alternate and you set to Y specifically to use the alternate code. (or have more than one action value to determine which block(s) of code get used)

If you have a very small number of data sets you might provide them as a single list variable: setlist= instead of/in addition to altfolder and altsets.

 

Note: Zip name is not a valid macro parameter name so you should be careful providing examples.

 

By 'other folder' I really hope you mean "different library or libraries"  or you may be causing yourself more work using long paths instead of library names.

Patrick
Opal | Level 21

It's technically not a problem to add files from multiple folders to a zip archive but it's something the macro you're using would need to support. Does this macro also have parameters for adding additional files to an existing zip archive? 

 

If this is some infrastructure macro someone in your organization wrote and maintains then best ask this person/department how to go about your requirement. This will help you to implement according to your companies design principles - and/or it might motivate the author of the code to add additional functionality to an existing infrastructure macro.
If it's a macro you've got from the Internet then please share the macro code or location where you got it from.

 

IF this is a requirement you only have for a specific use case then could also write some additional code after the macro call to add additional files from other folders to the created zip archive. Here a SAS Blog that provides the details: Add files to a ZIP archive with FILENAME ZIP

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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