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;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 2 replies
  • 1017 views
  • 2 likes
  • 3 in conversation