I am trying to create multiple oservations from single observation as follows.
Can someone please provide SAS codes? Thanks.
From:
id var1 yr
000000001 1 1997
000000001 2 1998
000000001 3 1999
000000001 4 2002
000000002 5 2007
000000003 6 2001
000000003 7 2003
To:
000000001 1 1997
000000001 2 1998
000000001 3 1999
000000001 3 2000
000000001 3 2001
000000001 4 2002
000000002 5 2007
000000003 6 2001
000000003 6 2002
000000003 6 2003
Your example to: data doesn't explain what you are trying to accomplish. However, the following code should provide enough clues to accomplish what you want:
data want (drop=last: v1 year);
set have (rename=(yr=year var1=v1));
lastyear=lag(year);
lastv1=lag(v1);
if not missing(lastyear) and year ne lastyear+1 then do;
var1=lastv1;
do yr=lastyear+1 to year-1;
output;
end;
end;
var1=v1;
yr=year;
output;
run;
HTH,
Art
this is a nice example art297.
To people like me who didn't know the "lag" function, it tells you the value from the record before. This is a nice feature to avoid the "retain" function.
Or use merge skill mentioned by Peter.C
data temp; input id : $10. var1 yr ; cards; 000000001 1 1997 000000001 2 1998 000000001 3 1999 000000001 4 2002 000000002 5 2007 000000003 6 2001 000000003 7 2003 ; run; data want(drop=_yr i _id); merge temp temp(keep=yr id rename=(yr=_yr id=_id) firstobs=2); output; if _yr-yr gt 1 and id=_id then do; do i=yr+1 to _yr-1; yr=i; output; end; end; run;
Ksharp
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 16. Read more here about why you should contribute and what is in it for you!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Select SAS Training centers are offering in-person courses. View upcoming courses for: