简体   繁体   中英

SAS - Using Global Normalization Factor w/o Using Macro Variable

Disclaimer: This is mostly a style/best practices question as I do have a functional solution using a macro variable (outlined below) and thus may be inappropriate for this site.

Given a dataset of non-normalized risk scores, eg:

Dataset_1:

Person, Score
A, 1.00
B, 4.00
C, 2.35
...

I would like to normalize such that the arithmetic average is 1.0. I could summarize this dataset, developing the average risk score and divide each observation by that risk score. For example:

Proc Summary ....; yielding the dataset with one observation:

Dataset_2:

Avg_Score
2.5

Then use:

Data _null_; Set Dataset_2;
  Call Symput("NormFactor", Avg_Score);
Run;

And:

Data NormalizedScores;
  Set Dataset_1;
  Score_Norm = Score / &NormFactor.;
Run;

However, this seems like trash code to me. Is there a better way of doing this?

If you want to do it the old fashioned way, there is a better way than the macro variable; just merge the datasets, or else set them if there's just one mean. (Merge if you have a BY variable.)

For example:

data dataset_1;
input Person $ Score;
datalines;
A 1.00
B 4.00
C 2.35
;
run;
proc means data=dataset_1 noprint;
  var score;
  output out=dataset_2 mean=avg_score;
run;


Data NormalizedScores;
  set dataset_1;
  if _n_=1 then set dataset_2;
  Score_Norm = Score / avg_score;
Run;

Variables that come from a SET statement are retained automatically, and since we only read in the second dataset once, they're not replaced or set to missing.

The more slick way would be to use PROC STDIZE , which is the newer version of PROC STANDARD , but it's not clear to me if there's a particular method that does precisely what you want.

Try PROC STANDARD

data test;
input Person $ Score;
datalines;
A 1.00
B 4.00
C 2.35
;

proc standard data=test out=test2 mean=1;
var Score;
run;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM