Hello to all,
In order to send files to external systems I have to do signons on some sas servers that communicate with external systems.
In particular my problem lies in the fact that during the signons with which I copy files from one server to another I can not solve the variable macro with the file name. Attached is the sample code.
The resolution function in the first signon in the second no
Will someone please help me?
%macro invio;
proc sql;
create table INSPECTION_FOR_SPM as
select *
from dati.HSEQ4A_KPI_X_SPM
where Event_Date='202310';
quit;
data _null_;
date_=put(intnx('month',today(),-1),monyy7.);
put date_;
data_comp=compress(('SPM_KPI_HSEQALL_'||date_||'.csv'));
put data_comp;
call symput('file',data_comp);
run;
%let nome_file=&file.;
%put nome file--------------->&file.;
proc export data=INSPECTION_FOR_SPM outfile="/sasgrid/hseq/1_0/KPI_HSEQ4ALL_X_SPM/&nome_file." dbms=dlm replace label;
delimiter='|';
run;
/********************invio tramite sftp***************************/
filename locref "/sasgrid/hseq/1_0/KPI_HSEQ4ALL_X_SPM/&nome_file.";
%let host=xxxxxxxxxx 7551;
options comamid=tcp remote=host noconnectmetaconnection;
signon userid="xxxxxxx\zsassystemuserdcc" password="{SAS002}03079E1140FD8F163EF93EB41335DE5D0D5A90AA49A7ED19";
%syslput file1=&nome_file.;
rsubmit;
options NETENCRALG=SSL;
filename outref "G:\&file1.";
Proc Upload
infile=locref
outfile=outref BINARY;
run;
data _null_;
call symput('host','elaawgsasa12.global 17551');
run;
options comamid=tcp remote=host noconnectmetaconnection;
signon userid="sassrv" password="sassrvadm";
filename locref "G:\&file2";
rsubmit;
filename outref "/sasgrid/hseq/1_0/KPI_HSEQ4ALL_X_SPM/&file2.";
Proc Upload
infile=locref
outfile=outref BINARY;
run;
/*
filename out sftp "/01_IMPORTED_KPI/&file2." host='ftp-enl.bravosolution.com' debug
cd='/01_IMPORTED_KPI/' user='enlusr01160' optionsx='-i /home/sassrv/.ssh/SPM_PVTK.ppk';
data _null_;
infile "/sasgrid/hseq/1_0/KPI_HSEQ4ALL_X_SPM/&file2." recfm=n ;
input x $char1. @@;
file out recfm=s;
put x $char1. @@;
run;
*/
endrsubmit;
endrsubmit;
%mend;
%invio;
Best is to remove the macro.
This simple example program works fine when submitted as "open" code:
%let mvar=local session;
%syslput mvar=remote1;
rsubmit remote1;
%put &=mvar;
endrsubmit;
Log
133 %let mvar=local session; 134 %syslput mvar=remote1; 135 rsubmit remote1; NOTE: Remote submit to REMOTE1 commencing. 9 %put &=mvar; MVAR=remote1 NOTE: Remote submit to REMOTE1 complete.
But if you try that inside a macro.
%macro test1;
%let mvar=local session;
%syslput mvar=remote1;
rsubmit remote1;
%put &=mvar;
endrsubmit;
%mend test1;
%test1;
The %PUT runs on the LOCAL session.
143 %test1; MPRINT(TEST1): rsubmit; NOTE: Remote submit to REMOTE1 commencing. MVAR=local session MPRINT(TEST1): endrsubmit; NOTE: Remote submit to REMOTE1 complete.
If you just use %NRSTR() to protect the remote macro macro code:
%macro test2;
%let mvar=local session;
%syslput mvar=remote1;
rsubmit remote1;
%nrstr(%put &=mvar;)
endrsubmit;
%mend test2;
%test2;
It will print the value of the remote macro variable.
151 %test2; MPRINT(TEST2): rsubmit; NOTE: Remote submit to REMOTE1 commencing. MPRINT(TEST2): %put &=mvar; MPRINT(TEST2): endrsubmit; 10 %put &=mvar; MVAR=remote1 NOTE: Remote submit to REMOTE1 complete.
Could you be more specific? Exactly which macro variable, on which line of the code, isn't resolving properly?
Hi have problem with the resolution this macro variable &nome_file. when I use the signon for copy the file to another server.
I try to use the %syslput ma this way resolve the macro variabile only first signon, while in the second signon :
data _null_;
call symput('host','elaawgsasaxxxx 17551');
run;
%syslput file2=&file1.; /************don't resolve the value ************/
options comamid=tcp remote=host noconnectmetaconnection;
signon userid="sassrv" password="sassrvadm";
filename locref "G:\&file2";
rsubmit;
filename outref "/sasgrid/hseq/1_0/KPI_HSEQ4ALL_X_SPM/&file2.";
Proc Upload
infile=locref
outfile=outref BINARY;
run;
What is the value of &file1 just before the %SYSLPUT command?
Please put the command
%put &=file1;
in your code, before %SYSLPUT and run it and show us the results of this command.
If you are having trouble with the new(ish) %SYSLPUT statement you might try using the old autocall macro that SAS used to provide to send a macro variable to a remote session.
Here is a copy of the version that shipped with SAS 6.12
https://github.com/sasutils/macros/blob/master/syslput612.sas
Did you try it without the MACRO wrapper?
It is probably the macro that is resolving the macro variable reference at the wrong time.
Best is to remove the macro.
This simple example program works fine when submitted as "open" code:
%let mvar=local session;
%syslput mvar=remote1;
rsubmit remote1;
%put &=mvar;
endrsubmit;
Log
133 %let mvar=local session; 134 %syslput mvar=remote1; 135 rsubmit remote1; NOTE: Remote submit to REMOTE1 commencing. 9 %put &=mvar; MVAR=remote1 NOTE: Remote submit to REMOTE1 complete.
But if you try that inside a macro.
%macro test1;
%let mvar=local session;
%syslput mvar=remote1;
rsubmit remote1;
%put &=mvar;
endrsubmit;
%mend test1;
%test1;
The %PUT runs on the LOCAL session.
143 %test1; MPRINT(TEST1): rsubmit; NOTE: Remote submit to REMOTE1 commencing. MVAR=local session MPRINT(TEST1): endrsubmit; NOTE: Remote submit to REMOTE1 complete.
If you just use %NRSTR() to protect the remote macro macro code:
%macro test2;
%let mvar=local session;
%syslput mvar=remote1;
rsubmit remote1;
%nrstr(%put &=mvar;)
endrsubmit;
%mend test2;
%test2;
It will print the value of the remote macro variable.
151 %test2; MPRINT(TEST2): rsubmit; NOTE: Remote submit to REMOTE1 commencing. MPRINT(TEST2): %put &=mvar; MPRINT(TEST2): endrsubmit; 10 %put &=mvar; MVAR=remote1 NOTE: Remote submit to REMOTE1 complete.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.