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

Hi all,

 

Normally, we got the mean from proc means by the average of the variables in a group of call variables called from statement "BY".

I also did the same thing

proc means data=inter noprint;
by LOC year;
var amihud;
output out=agg_amihud_ew  mean=agg_mh_ew_year;
run;

So,agg_mh_ew_year will be calculated by the average of all firms's amihud in one country in one year. However, what I want is to calculate agg_amh_ew_year that total of all firms'amihud this year divide by the number of firms in one country last year. I think that it will relate to the variable _FREQ_ but I do not know how to adjust the code. Could you please help me to sort it out?

 

My novice idea is to create a datastep and then create the lag_freq, then I calculated the desired variable based on multiplying to_FREQ_ and then divide to lagfreq. Is there any other shorter idea though?

Warmest regards.

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 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Using results from other values of Class or By variables means that you will need to take the results into a data step and use Lag functions or possibly use Proc SQL with a reflexive join (a table with itself) on something like

 

On t1.loc = t2.loc

    and t1.year=(t2.year-1)

 

"shorter" depends on the complexity.

 

Not that it reduces the complexity, such as it may be of the code, but you can request the N= statistic so you have some "nicer" than _freq_ if you don't like the variable name.

View solution in original post

1 REPLY 1
ballardw
Super User

Using results from other values of Class or By variables means that you will need to take the results into a data step and use Lag functions or possibly use Proc SQL with a reflexive join (a table with itself) on something like

 

On t1.loc = t2.loc

    and t1.year=(t2.year-1)

 

"shorter" depends on the complexity.

 

Not that it reduces the complexity, such as it may be of the code, but you can request the N= statistic so you have some "nicer" than _freq_ if you don't like the variable name.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 602 views
  • 1 like
  • 2 in conversation