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

I'd like to know how to scale a variable between 0&1 in sas. Perhaps it's possible to do with proc stdize somehow?

1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ

If you want a linear transformation that maps your data to [0,1], use

proc stdize data=MyData out=StdOut method=RANGE;

   var vrp;

run;

This maps min(vrp) to 0 and max(vrp) to 1. The transformation is

x --> (x - min(x))/range(x)

http://support.sas.com/documentation/cdl/en/statug/63962/HTML/default/viewer.htm#statug_stdize_sect0...

View solution in original post

11 REPLIES 11
ballardw
Super User

It will be helpful to provide a bit more detail on what you hope to accomplish.

carbs
Calcite | Level 5

I simply would like to make the variable vrp scaled between 0&1, the dataset is attached above if it helps..

Reeza
Super User

What are the rules for scaling between 0 and 1. How will both 116 and -118 map to the scale from 0 to 1?

You could just use the percentile, but depending on what you're doing that could make absolutely no sense.

carbs
Calcite | Level 5

I need the variable vrp for my time-varying regression:

proc reg data=spainbj outest=brittenjonesspain;

model Identity= MKT MKT*lag(vrp) SMB SMB*lag(vrp) HML HML*lag(vrp) MOM MOM*lag(vrp)/noint;

run;

this is a britten-jones regression, where betas are portfolio weights. I use the variable vrp to make the portfolio weights time-varying according to lagged value of vrp. Now I need to scale the variable vrp, in order to get the portfolio weights/betas to change in a rational way. Hope this helps..

Ksharp
Super User

you want to standardize this variable to avoid the influence of  scale?

proc stdize will help you. Sure there is also a function looks like stdize() to do it.

Ksharp

carbs
Calcite | Level 5

Yes! I tried the proc stdize but couldn't get it working. Would someone be able to give me an example on how to proceed with the code here? Thanks in advance.

Rick_SAS
SAS Super FREQ

If you want a linear transformation that maps your data to [0,1], use

proc stdize data=MyData out=StdOut method=RANGE;

   var vrp;

run;

This maps min(vrp) to 0 and max(vrp) to 1. The transformation is

x --> (x - min(x))/range(x)

http://support.sas.com/documentation/cdl/en/statug/63962/HTML/default/viewer.htm#statug_stdize_sect0...

carbs
Calcite | Level 5

wow, that was easy! Thanks rick!

carbs
Calcite | Level 5

If I'd like to make the linear transformation between -1 and 1, how could that be done? Checked the methods from Rick's link, but none of them seem to fit this idea straight...

Rick_SAS
SAS Super FREQ

Run PROC STDIZE with METHOD=RANGE. That creates a variable on [0,1].

Then run a data step that sends x --> 2*x-1. The new range is [-1,1]. For example:

data StdOut;

set StdOut;

vrp = 2*vrp - 1;

run;

carbs
Calcite | Level 5

easy again, thanks a million rick!

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 11 replies
  • 15035 views
  • 7 likes
  • 5 in conversation