Hi SAS community,
Thank you for your dedicated helps recently, I learn a lot from it, I will try my best to upgrade my skills better to help the others in the future.
Now, I have the data as below:
.
.
.
.
while Type is the column of different stocks (character variables), others are numeric variables (daily data from1/1/1987 to 31/12/2019).
From this dataset have, I want to get the data of p_us, up_us, nosh at the end of each year for each stock (distinct Type).
My code is as below:
data want ;
set have;
by Type year;
if last.year then
do;
p_us_=p_us;
vo_=vo;
nosh_=nosh;
end;
else delete;
run;
And when summarising the results that I receive, I saw that the data for vo, trading_vol, amihud, vo_ ends up with 0 observation as the proc means indicates below:
proc means data=have;
title"have";
run;
proc means data=want;
title"want";
run;
I also check my logic in my code but cannot find out the reason why it ends up like that, can you please have a look and point me out what should be the possibilities of such a result?
Thanks in advance!
Your data step keeps only the very last observation of each year for a type. Looks like your variables are always missing on these last observations.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.