Hi Folks:
I've never used proc iml before and trying to use the approach suggested in the Wicklin's blog.
I have a dataset with a variable with negative values which needs to be log transformed.
data have;
input var;
cards;
-1
-2
;
And this step was suggested. Can you help me understand how I am supposed use the proc iml approach suggested so that variable 'var' with negative values in my 'have' dataset is translated and log transformed?
proc iml; Y = {-3,1,2,.,5,10,100}; /* negative datum */ LY = log10(Y + 1 - min(Y)); /* translate, then transform */
Reeza, I get the following error. Also, after transforming the variable min_min_temp, then, how to integrate this vector back to my data set run my model on? I'm dumb founded. Is it possible that you showcase on the 'have' data, please ?
data have;
input date min_min_temp max_max_temp;
cards;
20454 -5.9 12
20455 -2.7 16.8
20456 -2.3 16.6
20457 -3.2 15.2
20458 -6.1 11.1
20459 -7.8 9.9
20460 -7.6 8.5
20461 -8.9 7.5
20462 -6.2 9.4
20463 -3.9 10.9
;
5296 proc iml;
NOTE: IML Ready
5297 use weather1;
5298 read var {min_min_temp};
5299 Y = {min_min_temp};
5299! /* negative datum */
5300 Log_min_temp = log(Y + 1 - min(Y));
ERROR: (execution) Numeric argument should be character.
operation : + at line 5300 column 22
operands : Y, *LIT1003
Y 1 row 1 col (character, size 12)
MIN_MIN_TEMP
*LIT1003 1 row 1 col (numeric)
1
statement : ASSIGN at line 5300 column 1
5300!
1. Run a proc means to get the minimum for each variable you want to analyze
2. Merge that in to your data
3. Set up two arrays, one for the raw data and one for the transformed data
4. Set up an array for the means (temporary is also good, but not really needed)
4. Loop through and do your transformations
Adding summary statistics to a data set
https://github.com/statgeek/SAS-Tutorials/blob/master/add_average_value_to_dataset.sas
Here's a tutorial on using Arrays in SAS
https://stats.idre.ucla.edu/sas/seminars/sas-arrays/
And an entirely different suggestion - look into the options in PROC STDIZE for data transformations but none seem close to what you want to do. Just something to keep in mind though.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.