Hi all SAS Users,
Normally, Output out statement in PROC MEANS only show us the variables called by "BY" statement, and mean, sum,..... called by statement Output out
Can you please tell me how can I tag along another variable call "LOC" to the output here?
So, I have a original dataset called chl_d. The frequency is daily, LOC is 3 characters indexed for a country.
A part is like that
GVKEY IID DATADATE CIK CONML LOC SIC ISIN SEDOL EXCHG AJEXDI CSHOC CSHTRD CURCDD PRCCD PRCHD PRCLD PRCSTD TPCI TRFD ex_rate gviidkey prccd_abs prccd_abs_ lagprccd_abs_ lagajexdi lagtrfd raw_return log_raw_return i raw_return_abs dollar_vol prccd_ prchd_ prcld_ appday eta c eta_lead1 year S_2DC
001166 01W 04JAN1999 0000351483 ASM International NV NLD 3559 NL0000334118 5165294 104 1.0000 33724343.0000 45145.0000 EUR 4.5000 4.6000 4.4500 10 0 1 0.84753 001166_01W 4.5 5.3095465647 . . . . . 85 . 239699.47966 5.3095465647 5.4275364884 5.2505516029 1 1.674909242 1.6695064389 1.673635762 1999 0.0094466755
001166 01W 05JAN1999 0000351483 ASM International NV NLD 3559 NL0000334118 5165294 104 1.0000 33724343.0000 32047.0000 EUR 4.5000 4.6000 4.4500 10 0 1 0.84861 001166_01W 4.5 5.3027892672 5.3095465647 1 1 -0.127266942 . 85 0.1272669424 169938.48764 5.3027892672 5.4206290286 5.2438693864 1 1.673635762 1.6682329589 1.7264615191 1999 0.0354737899
001166 01W 06JAN1999 0000351483 ASM International NV NLD 3559 NL0000334118 5165294 104 1.0000 33724343.0000 550752.0000 EUR 4.7000 5.0000 4.6000 10 0 1 0.85324 001166_01W 4.7 5.5084149829 5.3027892672 1 1 3.8776897473 1.3552395503 85 3.8776897473 3033770.5687 5.5084149829 5.8600159392 5.3912146641 1 1.7264615191 1.7062769199 1.7121731718 1999 0.02181866
001166 01W 07JAN1999 0000351483 ASM International NV NLD 3559 NL0000334118 5165294 104 1.0000 33724343.0000 323750.0000 EUR 4.8500 4.9000 4.6000 10 0 1 0.85682 001166_01W 4.85 5.660465442 5.5084149829 1 1 2.7603305046 1.0153504206 85 2.7603305046 1832575.6868 5.660465442 5.7188207558 5.3686888728 1 1.7121731718 1.7335061224 1.815432897 1999 0
I use the code below to get the yearly results, however, the results chl_2d_year just contain some variables, I do not know how to output the variable LOC in chl_2d_year.
/*Calculating CHL for each firm per year*/
proc means data=work.chl_d noprint;
by gviidkey year;
var S_2DC appday;
Output out=chl_2d_year (keep=gviidkey year CHL_2d_c appdaysum where=(appdaysum >=12))
mean=CHL_2d_c sum=SC APPDAYSUM;
/*Explain: mean of all S_2DC of one company in a year is called CHL
sum SC APPDAYSUM means SC is sum of S_2DC and APPDAYSUM is sum of APPDAY*/
run;
The result is like that
gviidkey year CHL_2d_c APPDAYSUM
001166_01W 1999 0.0141318615 253
001166_01W 2000 0.0175846612 249
001166_01W 2001 0.0167945019 252
001166_02W 1999 0.0172477814 105
001166_02W 2000 0.0311273775 143
001166_02W 2001 0.0291985294 84
001855_03W 1999 0.0434634019 86
001855_03W 2000 0.0578536264 42
001855_03W 2001 0.1417332222 24
001932_01W 1999 0.0125657319 252
What I want is to insert the column LOC from chl_d to chl_2d_year. Could you please hint me how to do that?
Warmest regards.
Hi @Phil_NZ,
I think you can use the ID statement (I would like to include a link to the documentation, but the website seems to be down):
id LOC;
Of course, you also need to add LOC to the KEEP= dataset option.
Edit: Here's an excerpt from the offline help (note that "maximum" refers to alphabetical order in case of character variables such as LOC):
identifies one or more variables from the input data set whose maximum values for groups of observations PROC MEANS includes in the output data set.
You need to merge it in in a separate step. As mentioned in your other thread, SAS procedures won't do anything that is not in their predefined capabilities.
Hi @Phil_NZ,
I think you can use the ID statement (I would like to include a link to the documentation, but the website seems to be down):
id LOC;
Of course, you also need to add LOC to the KEEP= dataset option.
Edit: Here's an excerpt from the offline help (note that "maximum" refers to alphabetical order in case of character variables such as LOC):
identifies one or more variables from the input data set whose maximum values for groups of observations PROC MEANS includes in the output data set.
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.