BookmarkSubscribeRSS Feed
aidant01
Fluorite | Level 6

Hi everyone, 

 

I would like assistance with the following.  For example, for by group account=X and ticker=A, there is a gap between date 1/1/2015 and 1/5/2015. I would like to add rows for 1/2/2015 through 1/4/2015 by taking the non-date values from row of 1/1/2015. I've attached an excel example for reference. Any help will be appreciated. Thank you.

 

      
Have     
      
 AccountTickerDateOutstanding SharesPrice
 XA01/01/15100$1
 XA01/05/15200$2
 XB01/01/15300$3
 XB01/05/15600$6
      
Want     
      
 AccountTickerDateOutstanding Shares 
 XA01/01/15100$1
 XA01/02/15100$1
 XA01/03/15100$1
 XA01/04/15100$1
 XA01/05/15200$2
 XB01/01/15300$3
 XB01/02/15300$3
 XB01/03/15300$3
 XB01/04/15300$3
 XB01/05/15600$6
      
      
      
      
5 REPLIES 5
Astounding
PROC Star

Do you want all weekdays, or do you have a list of holidays that you would like to skip over?

novinosrin
Tourmaline | Level 20

Hi @aidant01   This is a cheeky solution deliberately to avoid gymnastics using temp vars to hold values. See if this works or in any event , sas communities will offer you better

 

data have;	 	 	 	 
input Account $	Ticker $	Date	:mmddyy10. OutstandingShares	Price dollar2.;
format date mmddyy10. Price dollar2.;
cards;
X	A	01/01/15	100	$1
X	A	01/05/15	200	$2
X	B	01/01/15	300	$3
X	B	01/05/15	600	$6
	;
proc sql;
create table temp as
select  Account ,Ticker,min(date) as mindate,max(date) as maxdate
from have
group by  Account ,Ticker;
quit;

data want;
if _n_=1 then do;
if 0 then set have;
 dcl hash H (dataset:'have') ;
  h.definekey  ("Account","Ticker","Date") ;
   h.definedata ("OutstandingShares", "price") ;
   h.definedone () ;
 end;
set temp;
do date=mindate to maxdate;
rc=h.find();
output;
end;
drop rc mindate maxdate;
run;
PGStats
Opal | Level 21

Proc expand (part of SAS/ETS) does just this, and other kinds of, interpolation:

 

proc expand data=have out=want to=day;
by account ticker;
id date;
convert oshares price / method=step observed=beginning;
run;
PG
Ksharp
Super User
data have;	 
infile cards expandtabs truncover; 
input Account $	Ticker $	Date	:mmddyy10. OutstandingShares	Price dollar2.;
format date mmddyy10. Price dollar2.;
cards;
X	A	01/01/15	100	$1
X	A	01/05/15	200	$2
X	B	01/01/15	300	$3
X	B	01/05/15	600	$6
;
data want;
 merge have have(keep= Account	Ticker	Date
 rename=( Account=A	Ticker=T Date=D) firstobs=2);
 output;
 if Account = A and Ticker = T then do;
   do Date=Date+1 to D-1 ;
    output;
   end;
 end;
 drop A T D;
 run;

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 5 replies
  • 2555 views
  • 3 likes
  • 5 in conversation