BookmarkSubscribeRSS Feed
dkewon
Calcite | Level 5

Hi all,

 

I have a link that looks like this -  https:// ... (year)...(month).xslm. 

 

The month part of the link changes every month. Is there any way SAS can click, download a file from this URL, and save it to our file system?

 

I can schedule a job, but I just can't figure out how to make SAS save this file to our file system. I tried PROC HTTP GET request but had no luck. 

 

Thank you for your help!

 

3 REPLIES 3
Reeza
Super User
filename _myfile "/home/fkhurshed/downloaded_data%sysfunc(today(), year4.)_%sysfunc(today(), monname3.).xlsm";
 
proc http method="get" 
 url="https://www.noaa.gov........%sysfunc(today(), year4.)_%sysfunc(today(), monname3.).xlsm"
 out=_myfile
;
run;
 
filename _myfile clear;

First get this working for a single file with hardcoded dates, something like above. 
Then use %SYSFUNC() with today() and the appropriate format for your date structure to have the date values calculated automatically. 

yabwon
Onyx | Level 15

If you want to get a binary copy of the "online" file, do it like this: 

 

%let year=2023;
%let month=June;


filename in URL "https:// ... (&year.)...(&month.).xslm" 
recfm=N lrecl=1; /* this important for binary copy */

filename out "/path/to/store/the/file/ filename (&year.)...(&month.).xslm" recfm=N lrecl=1;

data _null_;
rc = fcopy("in", "out");
rctxt = sysmsg();
if rc then 
  put "ERROR:" rctxt;
run;

filename in clear;
filename out clear;

I'm using this technique in my programs. 

 

All the best

Bart

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1227 views
  • 2 likes
  • 4 in conversation