I successfully run the code below, my file gets saved into the 2020 folder.
But when I substitute 2020 with &TargetYear I get no output. I have tried multiple combinations of quotes, no help.
data _null_;
%global TargetYear;
year = year(input("&sysdate9",date9.));
Call symput("TargetYear", year);
%put &TargetYear;
run;
data _null_;
CALL SYSTEM("lftp
ftps://xxxx:xxxxx.com
-e 'cd mysite/vcr/from/2020;
put /prd/data/LAST5_VISIT_HRS.html;
quit;'");
run;
Simplify your step, and use call symputx:
data _null_;
call symputx("TargetYear", year(today()),'g');
run;
data _null_;
call system(
"lftp ftps://xxxx:xxxxx.com -e 'cd mysite/vcr/from/2020;put /prd/data/LAST5_VISIT_HRS.html; quit;'"
);
run;
Call symputx automatically strips the value it stores in the macro variable.
You create a macro variable, but you never use it.
You also use the %put incorrectly; since it is part of the data step code, it is resolved before the data step runs and creates &targetyear. You need to move it past the run; statement to be effective.
data _null_;
%global TargetYear;
year = year(input("&sysdate9",date9.));
Call symput("TargetYear", year);
%put &TargetYear;
run;
data _null_;
CALL SYSTEM(%sysfunc(quote(lftp
ftps://xxxx:xxxxx.com
-e "cd mysite/vcr/from/&TargetYear;
put /prd/data/LAST5_VISIT_HRS.html;
quit;"));
run;You can use the quote function.
Thank you for the reply, your code ran well after adding an extra parenthesis: quit;")));
Simplify your step, and use call symputx:
data _null_;
call symputx("TargetYear", year(today()),'g');
run;
data _null_;
call system(
"lftp ftps://xxxx:xxxxx.com -e 'cd mysite/vcr/from/2020;put /prd/data/LAST5_VISIT_HRS.html; quit;'"
);
run;
Call symputx automatically strips the value it stores in the macro variable.
Thanks a lot, as you mentioned, this was a fundamental issue with making the macro variable persistent, thanks!
data _null_;
call symputx("TargetYear", year(today()),'g');
run;
data _null_;
call system(
"lftp ftps://xxxx:xxxxx.com -e 'cd mysite/vcr/from/&TargetYear;put /prd/data/LAST5_VISIT_HRS.html; quit;'"
);
run;
It's your turn to help shape SAS Innovate 2027. Share your expertise and inspire the SAS community.
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.