/* Program to demonstrate the log-modulus transformation "A log transformation of positive and negative values" by Rick Wicklin http://blogs.sas.com/content/iml/2014/07/14/log-transformation-of-pos-neg/ Example data from http://www.governing.com/gov-data/census/2010-census-state-migration-statistics.html */ data NetCA2011; input State $21. Abbrev $2. In Out Population; label In = "Number moving to CA from State" Out = "Number moving to State from CA" Net = "Net Change in CA Population" Population = "Population of State" LogNet = "Net Immigration" Pop = "Population (millions)"; Net = In - Out; Pop = Population / 1e6; /* measure in millions */ LogNet = sign(Net)*log10( abs(Net)+1 ); datalines; Alabama AL 2087 3389 722718 Alaska AK 7358 3098 2937979 Arizona AZ 35650 49635 4802740 Arkansas AR 2648 4077 6482505 California CA . . 37691912 Colorado CO 21245 23234 5116796 Connecticut CT 3073 3699 3580709 Delaware DE 1302 699 907135 District of Columbia DC 3240 3797 617996 Florida FL 22094 22420 19057542 Georgia GA 13303 14949 9815210 Hawaii HI 9864 10173 1374810 Idaho ID 4796 9021 1584985 Illinois IL 20834 13930 12869257 Indiana IN 4673 7649 6516922 Iowa IA 3324 3297 3062309 Kansas KS 2810 4743 2871238 Kentucky KY 1201 2130 4369356 Louisiana LA 3600 3957 4574836 Maine ME 1658 829 1328188 Maryland MD 7793 8595 5828289 Massachusetts MA 10244 11556 6587536 Michigan MI . 7793 9876187 Minnesota MN 5687 6638 5344861 Mississippi MS 2092 4723 2978512 Missouri MO 7677 8386 6010688 Montana MT 2599 3033 998199 Nebraska NE 1955 5124 1842641 Nevada NV 36159 40114 2723322 New Hampshire NH 1222 547 1318194 New Jersey NJ 8053 5986 8821155 New Mexico NM 5904 7066 2082224 New York NY 25629 25761 19465197 North Carolina NC 8708 15373 9656401 North Dakota ND 1392 1356 683932 Ohio OH 10474 9032 11544951 Oklahoma OK 5113 8233 3791508 Oregon OR 18165 34214 3871859 Pennsylvania PA 8550 10672 12742886 Puerto Rico PR 1344 . 3706690 Rhode Island RI 1103 1949 1051302 South Carolina SC 5758 6592 4679230 South Dakota SD 1004 1286 824082 Tennessee TN 8761 7130 6403353 Texas TX 37087 58992 25674681 Utah UT 8944 18237 2817222 Vermont VT 745 819 626431 Virginia VA 15753 19371 8096604 Washington WA 36481 38421 6830038 West Virginia WV 832 1442 1855364 Wisconsin WI 5668 6637 5711767 Wyoming WY 2047 2539 568158 ; title "Immigration and Emigration to California (2011)"; proc sgplot data=NetCA2011; format Net Comma10.; scatter x=Pop y=Net / datalabel=Abbrev; xaxis grid max=25 offsetmax=0.05; yaxis grid values=(-20000 to 5000 by 5000) offsetmax=0.1 offsetmin=0.1; run; title "Log-Modulus Transformation"; data LogModulus; label y = "sign(x)*log10(|x| + 1)"; do x = -100 to 100; y = sign(x)*log10( abs(x)+1 ); output; end; run; proc sgplot data=LogModulus; series x=x y=y; xaxis grid values=(-100 -50 -10 0 10 50 100); yaxis grid values=(-2 to 2); run; /* For a discussion of using PROC SGPLOT to display log axes, see http://blogs.sas.com/content/iml/2014/07/09/scatter-plots-with-log-axes/ For a discussion of how to create custom tick marks for log axes, see http://blogs.sas.com/content/iml/2014/07/11/create-custom-tick-marks/ */ data Labels; input Net @@; LogNet = sign(Net)*log10( abs(Net)+1 ); datalines; -10000 -1000 -500 0 500 1000 10000 ; proc print;run; title "Net Population Change in California (2011)"; title2 "State-by-state Migration"; proc sgplot data=NetCA2011; scatter x=Pop y=LogNet / datalabel=Abbrev; xaxis type=log grid; yaxis grid values=(-4 -3 0 3 4) valuesdisplay=('-10,000' '-1,000' '0' '1,000' '10,000') offsetmin=0.05; run; title; title2;