BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
bwt
Calcite | Level 5 bwt
Calcite | Level 5

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

 

bwt_2-1602457434665.png

 

 

When i change the date format to show the full date it is 

 

bwt_3-1602457565379.png

 

Is there command i can run to make one row for each quarter?

 

Thanks

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

Use the ALIGN=END option in the proc expand statement.

PG

View solution in original post

4 REPLIES 4
PaigeMiller
Diamond | Level 26
You could change the code so this doesn't happen. Or you could change the dates before you do the merge so then you get one row per quarter. Or you could use PROC SUMMARY to produce one row per quarter.
--
Paige Miller
bwt
Calcite | Level 5 bwt
Calcite | Level 5

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;

mkeintz
PROC Star

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.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
PGStats
Opal | Level 21

Use the ALIGN=END option in the proc expand statement.

PG

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 4 replies
  • 625 views
  • 3 likes
  • 4 in conversation