BookmarkSubscribeRSS Feed
proc_talk
Fluorite | Level 6

I'm leveraging the SAS support article found here: https://support.sas.com/kb/24/670.html

 

But I'm trying to adapt the provided code to do a second '%if %sysfunc(exist(....' check for a zipped version of the same data set. I'm thinking like a GZIP file with a '.sas7bdat.gz' extension. Basically if the data exists (and is not zipped) do A, if the data exists (but is zipped) do B, or if the data exists in neither the zipped nor the non-zipped formats then do C. 

 

I've tried several different versions of the statement within the second 'exist()' statement, but I can't seem to get it right because in an instance where I should get a '1' in the log from the %put &need_to_unzip.;' statement, I'm keep getting the 'Data set &dsn. does not exist' statement back like it isn't checking the zipped option correctly.

 

I've tried  exist(&dsn.gz), exist(&dsn..gz), exist(&dsn.sas7bdat.gz), and exist(&dsn..sas7bdat.gz)

I'm thinking I need some sort of function or statement to indicate to SAS that it should be a zip file.

 

%macro checkds(dsn);
   %if %sysfunc(exist(&dsn)) %then %do;
      proc print data = &dsn;
      run;
   %end;
   %else %if %sysfunc(exist(&dsn.gz)) %then %do;
      %let need_to_unzip = 1;
      %put &need_to_unzip.;
   %end;
   %else %do;
      data _null_;
         file print;
         put #3 @10 "Data set &dsn. does not exist";
      run;
   %end;
%mend checkds;

%checkds(mylibrary.mytable)

 

2 REPLIES 2
SASKiwi
PROC Star

I don't think the EXIST function will work with zipped datasets as EXIST requires the use of the LIBNAME statement and AFAIK there is no ZIP option for a SAS library.

 

However, there is a ZIP method for the FILENAME statement. You could then use FEXIST to check if either the ZIP file or the member of a ZIP file exists. This won't tell you if it is a valid SAS dataset or not but at least you can unzip it if it exists and then maybe try EXIST.

Tom
Super User Tom
Super User

You are using two level name to reference that SAS dataset, mylib.mydataset, so you will need to figure out what filename that should be.

%let libref=%scan(work.&dsn,-2,.);
%let path=%sysfunc(pathname(&libref));
%let fname=&path/%sysfunc(lowcase(%scan(&dsn,-1,.))).sas7bdat.gz;
%if %sysfunc(fileexist(&fname))%then %do;
  %put Found a GZIP version of the file at &=fname ;
....
%end;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1574 views
  • 2 likes
  • 3 in conversation