BookmarkSubscribeRSS Feed
Phil_NZ
Barite | Level 11

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:

1.PNG

.

.

2.PNG

.

3.PNG

.

4.PNG

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;

result.PNG

 

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!

 
Thank you for your help, have a fabulous and productive day! I am a novice today, but someday when I accumulate enough knowledge, I can help others in my capacity.
1 REPLY 1
Kurt_Bremser
Super User

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.

How to Concatenate Values

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 1 reply
  • 756 views
  • 1 like
  • 2 in conversation