BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Espresso
Obsidian | Level 7

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

Accepted Solutions
Kurt_Bremser
Super User

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.

View solution in original post

5 REPLIES 5
Kurt_Bremser
Super User

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.

rudfaden
Lapis Lazuli | Level 10

 

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.

 

 

 

Espresso
Obsidian | Level 7

Thank you for the reply, your code ran well after adding an extra parenthesis:  quit;")));

Kurt_Bremser
Super User

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.

Espresso
Obsidian | Level 7

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;