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-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!

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.

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