DATA Step, Macro, Functions and more

filedialog sas 9.3 vs sas 9.4

Reply
Occasional Contributor
Posts: 9

filedialog sas 9.3 vs sas 9.4

Dear All,

 

I have a problem concerning 32bit vs 64bit in sas. (sas 9.3 vs sas 9.4)

 

I am using a procedure that allows me to open a filedialog for the users of my programs. (it is really user friendly)

i didnt write it my self (lex janssens was my inspiration). (see attachement).

 

In 9.4 it gives me problems.

i added dlltype=32 because apparently 9.4 is 64bit and cannot compile 32bit.

 

the program runs but it won't save the location of the file.

giving the error : you cannot use addr but have to use addrlong.

 

however changing addr to addrlong gives more errors.

 

Does anyone has a solution for this problem. (attachement has the program)

 

 

 

Attachment
Valued Guide
Posts: 505

Re: filedialog sas 9.3 vs sas 9.4

Select a file from a pop up dialog box and list the file

requires Python

inspired by ( this is a link to this message)
https://goo.gl/eKhTYt
https://communities.sas.com/t5/Base-SAS-Programming/filedialog-sas-9-3-vs-sas-9-4/m-p/345718

Doable in R but I like Python and SAS/WPS for these kinds of problems


HAVE ( A directory with some files (chose your own directory)
==============================================================

Directory of d:/txt

 fyl.txt
 hex.txt
 hexout.txt
 myfile.txt
 utf16le.txt
 UtlChkFyl.txt    ==> click on this one

WANT ( select and print file  )
===============================
  click on

       UtlChkFyl.txt

And this will appear in log

%macro utlchkfyl(file);
  %if %sysfunc(fileexist(&file)) ge 1 %then %do;
    %let rc=%sysfunc(filename(temp,&file));
    %let rc=%sysfunc(fdelete(&temp));
  %end;
%else %put The file &file does not exist;
%mend utlchkfyl;


WORKING CODE (PYTHON)
=====================

       fyl = tkFileDialog.askopenfilename(filetypes=[('Text files', '*.txt')]);

INVOCATION
==========

       %SelDir(c:/txt);

*          _       _   _
 ___  ___ | |_   _| |_(_) ___  _ __
/ __|/ _ \| | | | | __| |/ _ \| '_ \
\__ \ (_) | | |_| | |_| | (_) | | | |
|___/\___/|_|\__,_|\__|_|\___/|_| |_|

;

%macro SelDir(dir);

   %utl_submit_py64("
   import os;
   import tkFileDialog;
   import os;
   os.chdir('&dir');
   fyl = tkFileDialog.askopenfilename(filetypes=[('Text files', '*.txt')]);
   fo= open ('d:/txt/fyl.txt', 'w');
   fo.write(fyl+'\n');
   fo.close();
   ");

   * could also use filevar in infile;
   * but I think it is worth learning and using this method;

   data _null_;

    if _n_=0 then do;
     %let rc=%sysfunc(dosubl('
      data _null_;
         infile "d:/txt/fyl.txt";
         input;
         fylvar=strip(_infile_);
         call symputx("fyl",fylvar);
      run;quit;
    '));
    end;

     infile "&fyl";
     input;
     put _infile_;

   run;quit;

%mend SelDir;

%SelDir(d:/txt);


%macro utl_submit_py64(pgm)/des="Semi colon separated set of py commands";
  * write the program to a temporary file;
  filename py_pgm "%sysfunc(pathname(work))/py_pgm.py" lrecl=32766 recfm=v;
  data _null_;
    length pgm  $32755 cmd $1024;
    file py_pgm ;
    pgm=&pgm;
    semi=countc(pgm,';');
      do idx=1 to semi;
        cmd=compbl(cats(scan(pgm,idx,';')));
        if cmd=:'.' then cmd=substr(cmd,2);
        put cmd $char384.;
        putlog cmd $char384.;
      end;
  run;

  run;quit;
  %let _loc=%sysfunc(pathname(py_pgm));
  %put &_loc;
  filename rut pipe  "C:\Python_27_64bit/python.exe &_loc";
  data _null_;
    file print;
    infile rut;
    input;
    put _infile_;
  run;
  filename rut clear;
  filename py_pgm clear;
%mend utl_submit_py64;



Occasional Contributor
Posts: 9

Re: filedialog sas 9.3 vs sas 9.4

thanks for the reply but we dont have python.

Ask a Question
Discussion stats
  • 2 replies
  • 188 views
  • 0 likes
  • 2 in conversation