A good start to learning would be to learn the language itself - this is Base SAS. SQL can be used in a procedure, however it really only has usefulness if you are a) connecting to a database, or b) have some specific join.
Secondly, starting with macro and macro variables will not teach you anything other than bad coding techniques.
Thirdly, code formatting is far more important than what the code does. If a user can't read it then its useless.
I would also avoid named literals as much as possible - this being the "..."n. They are only useful if the database has names which are not SAS compliant, all other times use SAS specific.
Now your code can be written as:
data med1516 (keep=year dob medication treatment sex id startdate enddate amtdaysonmed);
set drugdata.year1516 in=a
drugdata.year1516 in=b
where medication=1;
if a then year=.;
else amtdaysonmed=enddate-startdate;
run;
For point 2, variables are created on the output data, so cannot be used in the current code, unless you use the keyword computed.
For point 3, yes, use proc sort, or if you have to use SQL, order by.