02-08-2018 09:25 AM
I've the following datasets in SAS and for the reporting I use only the previous year dataset (test_2017). Now I've to create a report which has data from 2016 to current year. It means I've to append the datasets (test_2016,test_2017 & test_2018) to create master dataset (test_2016_to_curr_year) which I will use for my reporting.
Appreciate if someone guide me to write the code dynamically to achieve my requirement.
02-08-2018 10:04 AM
You don't say how you currently combine the data but this should work:
set test_2016 - test_2018;
If there is a permanent library associated then don't forget to use the library.
The "dynamic" would have to be based on something to identify the start and end set but you don't really gain much if this is the only place the "dynamic" element would be used.
02-08-2018 11:29 AM
I just want to append the data and also I don't want to hard code the
current year value(i.e. 2018) and the I want the code to find it
So how do you determine the current year? Todays date or something else. Note this is not a snarky question because depending on who you work with "year" could be a fiscal year, School year which for some places a school year of "2017" means August 2016 to June 2017, or other "year" type (are you familiar with a "water year") which does not coincide with a calendar year.
If your data "year" names do not coincide with calendars then an explicit description would be needed to map a current date available from the Today function.
The second part would be how to determine the "start year". Is it fixed or do you want something that allows you to very going back 2, 3, 4 or more years?
02-08-2018 10:19 AM
I'm thinking on a macro where you can set initial and end years
%do i=&start %to &end;
proc append base=master data=test_&i.;
02-09-2018 10:44 PM
If all your datasets have a common name root, appended with a 4-digit year (as in test_2015 test_2016 ....), you can read them all without knowing the actual year ranges, with:
data want; set mylib.test_: ; run;
which will read all datasets whose names begin with TEST_.
This assumes there are no unwanted datasets in MYLIB whose name begins with TEST_.