Asim,

Does the following explanation and sample code help with the automation you're seeking?

The dates in the url are listed as period1 and period2. Note that these are not normal dates, but instead they are epoch* numbers. *The time in seconds from 1/1/1970.

https://query1.finance.yahoo.com/v7/finance/download/&stock.?period1=1535835578%str(&)period2=1538427578%str(&)interval=1d%str(&)events=history%str(&)crumb=&getCrumb."

SAS doesn’t natively convert epoch time to a date or vice versa, so we will need to convert these ourselves.
SAS calculates dates as the number of dates from 1/1/1960. Knowing this we can convert a SAS date to an epoch number. To do this we can start by creating some date macro variables and write a simple data step for the conversion.

%let begDate=01aug2018;
%let endDate=26aug2019;

data dates;
call symput('period1', "&begDate"d * 86400 - 315569260);
call symput('period2', "&endDate"d * 86400 - 315569260);
run;

What this is doing is:
1. Getting the amount of days of the defined date from 1/1/1960
2. We then multiply it by the number of seconds in a day (86,400)
3. Then subtract 315,569,260 seconds from the total. (We do this because there is a 10-year gap from 1/1/1960 and 1/1/1970. 315,569,260 is the average amount of seconds for 10 years *365.242 days per year*)
4. The new values are then stored in new macro that we can then add to the url

After the conversion and setting of the new macro variables, we can substitute the url as follows:

https://query1.finance.yahoo.com/v7/finance/download/&stock.?period1=&period1.%str(&)period2=&period2.%str(&)interval=1d%str(&)events=history%str(&)crumb=&getCrumb.