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;
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.