[prev in list] [next in list] [prev in thread] [next in thread]
List: sas-l
Subject: StackOverflow: Calling an interactive python application from a SAS macro all under DMS
From: Roger DeAngelis <rogerjdeangelis () GMAIL ! COM>
Date: 2017-03-28 1:50:56
Message-ID: 2291708063832495.WA.rogerjdeangelisgmail.com () listserv ! uga ! edu
[Download RAW message or body]
StackOverflow: Calling an interactive python application from a SAS macro all under \
DMS
No need to leave DMS, display manager system and the old text editor.
related to
https://goo.gl/ZUKYGN
http://stackoverflow.com/questions/43037876/want-to-develop-data-column-mapping-application-which-can-compare-column-names-f
http://effbot.org/tkinterbook/optionmenu.htm
HAVE (two SAS datasets. Second SAS dataset is missing Height and weight)
You do not knwo what is missing ahead of time
Up to 40 obs SD1.CLASS1 total obs=4
Obs NAME HEIGHT WEIGHT
1 Alfred 69.0 112.5
2 Alice 56.5 84.0
3 Barbara 65.3 98.0
4 Carol 62.8 102.5
Up to 40 obs from sd1.class2 total obs=4
Obs NAME Note: Height and weight missing
1 Alfred
2 Alice
3 Barbara
4 Carol
WANT ( POP up drop down list with variables in class1 not in class2 ie HEIGHT)
===============================================================================
+---+---------------+
> > -- [] [X] |
+---+---------------+
> >
> MISSING VARIABLES |
> >
> +---+ |
> > > HEIGHT |
> +---+ |
> >
> +---+ |
> > > WEIGHT |
> +---+ |
> >
> QUIT |
> >
+-------------------+
If I select Height I get detailed information in the log
on the variable I clicked on
NAME =HEIGHT
LIBNAME =SD1
MEMNAME =CLASS2
MEMTYPE =DATA
TYPE =num
LENGTH =8
NPOS =8
VARNUM =4
LABEL =
FORMAT =
INFORMAT =
IDXUSAGE =
SORTEDBY =0
XTYPE =num
NOTNULL =no
PRECISION =0
SCALE =.
TRANSCODE =yes
SOLUTION
========
This runs completely under the old text editor.
You can call python and it will build the interactive
display
* _ _ _
_ __ ___ __ _| | _____ __| | __ _| |_ __ _
> '_ ` _ \ / _` | |/ / _ \_____ / _` |/ _` | __/ _` |
> > > > > > (_| | < __/_____| (_| | (_| | || (_| |
> _| |_| |_|\__,_|_|\_\___| \__,_|\__,_|\__\__,_|
;
libname sd1 "d:/sd1";
options validvarname=upcase;
%symdel nams var /nowarn;
data sd1.class1;
set sashelp.class(keep=name height weight obs=4);
run;quit;
data sd1.class2;
set sashelp.class(keep=name obs=4);
run;quit;
proc sql;
select
quote(trim(name)) into :nams separated by ','
from
sashelp.vcolumn
where
libname='SD1'
and memname='CLASS1'
and name not in (
select
name
from
sashelp.vcolumn
where
libname='SD1'
and memname='CLASS2'
);
;quit;
%put &nams;
* _ _ _ _
_ __ _ _| |_| |__ ___ _ __ __ _(_)_ __ __| | _____ __
> '_ \| | | | __| '_ \ / _ \| '_ \ ____\ \ /\ / / | '_ \ / _` |/ _ \ \ /\ / /
> > _) | |_| | |_| | | | (_) | | | |_____\ V V /| | | | | (_| | (_) \ V V /
> .__/ \__, |\__|_| |_|\___/|_| |_| \_/\_/ |_|_| |_|\__,_|\___/ \_/\_/
> _| |___/
;
%utl_submit_py64old('
from Tkinter import *;
master = Tk();
var = StringVar(master);
var.set("Missing Variables");
option = OptionMenu(master, var, &nams);
option.pack();
def ok():;
. print(var.get());
. master.quit();
button = Button(master, text="OK", command=ok);
button.pack();
mainloop();
f = open("d:/txt/myfile.txt", "w");
f.write(var.get());
f.close();
');
* _ _ _ _ __
__ ____ _ _ __(_) __ _| |__ | | ___ (_)_ __ / _| ___
\ \ / / _` | '__| |/ _` | '_ \| |/ _ \_____| | '_ \| |_ / _ \
\ V / (_| | | | | (_| | |_) | | __/_____| | | | | _| (_) |
\_/ \__,_|_| |_|\__,_|_.__/|_|\___| |_|_| |_|_| \___/
;
data _null_;
if _n_ =0 then do;
%let rc=%sysfunc(dosubl(%nrbquote(
data _null_;
infile "d:/txt/myfile.txt";
input var $;
call symputx('var',var);
run;quit;
)));
end;
set sashelp.vcolumn(where=(
name="&var"
and memname="CLASS1"
and libname="SD1"
));
put (_all_) ( = $ /);
run;quit;
LIBNAME=SD1
MEMNAME=CLASS2
MEMTYPE=DATA
NAME=HEIGHT
TYPE=num
LENGTH=8
NPOS=8
VARNUM=4
LABEL=
FORMAT=
INFORMAT=
IDXUSAGE=
SORTEDBY=0
XTYPE=num
NOTNULL=no
PRECISION=0
SCALE=.
TRANSCODE=yes
%macro utl_submit_py64old(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=resolve(&pgm);
semi=countc(pgm,';');
do idx=1 to semi;
cmd=cats(scan(pgm,idx,';'));
if cmd=:'.' then cmd=substr(cmd,2);
put cmd $char96.;
putlog cmd $char96.;
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;
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic