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-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
  • 3 replies
  • 577 views
  • 2 likes
  • 4 in conversation