BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
dipand
Quartz | Level 8

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;
1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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.

 

View solution in original post

7 REPLIES 7
PaigeMiller
Diamond | Level 26

Could you be more specific? Exactly which macro variable, on which line of the code, isn't resolving properly? 

--
Paige Miller
dipand
Quartz | Level 8

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;

PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
dipand
Quartz | Level 8
I attached the program
Tom
Super User Tom
Super User

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

Tom
Super User Tom
Super User

Did you try it without the MACRO wrapper?

 

It is probably the macro that is resolving the macro variable reference at the wrong time.

Tom
Super User Tom
Super User

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.

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

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
  • 7 replies
  • 894 views
  • 0 likes
  • 3 in conversation