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

Alternatively you can do this. It is not as efficient, but it ensures that every relevant year is actually present for each firm.  

 

data have;
length code $10;
code='one';
do year=2000 to 2015;
   cashflow=rand('integer', 1000, 10000);
   output;
end;
code='two';
do year=2000 to 2013;
   cashflow=rand('integer', 1000, 10000);
   output;
end;
code='three';
do year=2000 to 2015;
   cashflow=rand('integer', 1000, 10000);
   output;
end;
run;

proc sort data=have;
   by code;
run;

proc transpose data=have out=temp prefix=year;
    by code;
    id year;
    var cashflow;
run;

data want(keep=code year cashflow);
   set temp;
   array years{*} year2000-year2015;
   if nmiss(of years[*])=0 then do i=1 to dim(years);
      cashflow=years[i];
      year=input(compress(vname(years[i]), '0123456789', 'k'), 8.);
      output;
   end;
run;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

What is Bayesian Analysis?

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 15 replies
  • 3101 views
  • 3 likes
  • 4 in conversation