DATA Step, Macro, Functions and more

Function to Scale Variables Based on a User-Defined Range

Reply
Contributor
Posts: 22

Function to Scale Variables Based on a User-Defined Range

Suppose I have the dataset below. Is there a function or technique that would allow me to scale each variable from 1 to 100 based upon user-defined (not actual) minimum and maximum values for each variable, respectively? For instance, I'd like a variable called Ratio_1_std that would score ratio_1 variables based upon how far they are into the range from 0 to 50. And I'd like a variable called Ratio_2_std that would score ratio_2 from 0 to 100 based upon a different range, perhaps 5 to 55. Values below the minimum and maximum provided would get scores of 1 and 100, respectively. I can simply code the desired results manually for each variable, but I'm looking for a potential function or technique that will do this based upon parameters I provide for each variable to minimize coding and to more easily apply this technique to many variables.

DATA WORK.TEMP;

INPUT ID RATIO_1 RATIO_2;

DATALINES;

1 25 50

2 5  10

;

RUN;

Super User
Posts: 17,784

Re: Function to Scale Variables Based on a User-Defined Range

Try Proc stdize and/or call stdize.

Proc if your standardizing down a column and call stdize if its across columns, i.e. a row.

Respected Advisor
Posts: 3,124

Re: Function to Scale Variables Based on a User-Defined Range

Still not sure if I have understand what you are after, it would be great if you can lay out some sample outcome based on your input data. But I have a feeling that you may want to check out PROC FCMP or DS2 custom method or simply PROC FORMAT.

Haikuo

Ask a Question
Discussion stats
  • 2 replies
  • 213 views
  • 0 likes
  • 3 in conversation