Hi There,
I have sourced two different data sets. One is quarterly and one is monthly. The quarterly data contains dates that are end of each quarter.
I have used Proc Expand to convert the monthly data in quarterly.
However upon converting the stored date value is different and even though i'm putting in 'observed=end' the stored date value is actually the beginning of the quarter.
Therefore when i merge there are multiple entries for each quarter. Below is the merged dataset
When i change the date format to show the full date it is
Is there command i can run to make one row for each quarter?
Thanks
Thanks - that would be great, are you able to let me know how to do this?
A) How do i change the dates before i merge them. Ie is there a function like in excel where i could make every date stored converted into an end of quarter value?
B) How could i change the code - below is what i've used:
proc expand data=housing2 out=temp1 from=month to=quarter;
id Date;
convert HP=HPqtr / observed = end;
run;
data combine;
merge temp1 temp2;
by date;
Run;
You want the last monthly record from housing2 in each quarter to merge with the quarterly data in temp2. You can do this without proc expand:
data want;
merge housing (keep=date in=inhousing)
temp2 (in=inqtr);
by date;
if inhousing=1 then set housing (rename=(date=m_date hp=hpqtr));
if inqtr ;
output;
** see note below ** call missing(of _all_);
run;
This will keep the latest monthly record per quarter, whose DATE is renamed to M_DATE so you will always know whether the most recent monthly data is actually the third month in each quarter.
If you have quarters with no matching months, this program will keep the last non-missing month from the prior quarter. If you don't want that, decomment the call missing statement.
Use the ALIGN=END option in the proc expand statement.
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!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.