Hi,
I have two datasets - ar.dataset_2018 and ar.dataset_2019. Please can someone finish off the code below (highlighted in red/whether set is the correct method) that would combine the two datasets (screenshot below shows an extract of the individual 2018 and 2019 datasets and the third table is an example of what I would like the merged dataset to look like), with the new dataset only containing records between 1st January 2018 and 31st May 2019 (which I have included in the code I have written so far - where '01Jan2018'd <= month <= '31May2019'd; )? Thanks!
Code
data datasets_2018_2019;
set ar.dataset_2018 ar.dataset_2019; /*What code to use to merge the two datasets, as shown by the screenshot?*/
where '01Jan2018'd <= month <= '31May2019'd;
run;
Not Tested.
Try
set ar.dataset_2018 ar.dataset_2019;
BY MONTH ID;
It appears that you are taking ALL the observations from your first data set, followed by ALL the observations from the second data set. If that's the case, you don't need a WHERE statement A simple DATA step would be sufficient:
data datasets_2018_2019;
set ar_dataset_2018 ar_dataset_2019;
run;
Note that using a WHERE statement assumes that the MONTH variable is actually a SAS date representing a particular day, and not just a month and year without a day.
Another possibility ... this would run faster but would use the name AR_DATASET_2018 to hold the combined version of the data:
proc append data=ar_dataset_2019 base=ar_dataset_2018;
run;
In the case of such small data sets, it seems like speeding up the program is not valuable, however.
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!
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.
Ready to level-up your skills? Choose your own adventure.