BookmarkSubscribeRSS Feed
mstell
Calcite | Level 5

Hi,

I've been searching for a solution for this problem for the past couple of days with no luck.

I have a data set with a column called mail_file that has a file paths to other SAS data sets.  I want to open those data sets and check to see if certain variables exist.

This is the code I came up with:

data lists;

     set list_to_load;

     dsid=open(mail_file, 'I' , , 'F');

    

     if dsid^=0 then

     do;

          if varnum(dsid, 'PROMOCODE')=0 then

               column_exists=1;

     end;

run;

I always get a dsid of 0.

The paths the of the files look like this: S:\Marketing\For_Output\listloadtest.sas7bdat.

Is there any way I can use a variable in the open() function? Or is there another approach I can take to acomplish this task?

Thanks a alot.

3 REPLIES 3
art297
Opal | Level 21

Your code appears to work if you leave off the extension.  e.g., try the following:

libname art "c:\art";

data art.test1;

  set sashelp.class;

  retain PROMOCODE (1);

run;

data art.test2;

  set sashelp.class;

run;

data art.test3;

  set sashelp.class;

  retain PROMOCODE (1);

run;

data list_to_load;

  informat mail_file $30.;

  input mail_file;

  cards;

c:\art\test1

c:\art\test2

c:\art\test3

;

data lists;

  set list_to_load;

  dsid=open(mail_file, 'I' , , 'F');

  if dsid^=0 then

  do;

       if varnum(dsid, 'PROMOCODE')=0 then

            column_exists=1;

  end;

run;

Tom
Super User Tom
Super User

Did you try quoting the filename?

   open(quote(trim(mail_file)),.....

Otherwise you will need to create a libref pointing the directory and then try to open the file using the traditional libname.member two level dataset name format.

fname=scan(mail_file,-1,'/\');

dir=substr(mail_file,1,length(mail_file)-length(fname));

member=scan(fname,1,'.');

libref='MYDATA';

rc=libname(libref,dir,,'access=readonly');

** test for error codes ?? ;

rc=open('MYDATA.'||member,.....)

...

mstell
Calcite | Level 5

Thanks for both of your responses!

I definitely needed the trim() function and it looks like the mode I using was not working correctly.

When I use open(trim(mail_file), , , 'F',) everything works as it should.

Thanks again.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 3 replies
  • 944 views
  • 6 likes
  • 3 in conversation