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

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 */

https://blogs.sas.com/content/iml/2011/04/27/log-transformations-how-to-handle-negative-data-values....

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
Y creates the vector there. You have a vector of -1, -2. You need to first load your data from a SAS data set into IML as a vector or matrix, since you only have one column a vector is fine. Then you can jump to the LY portion.

This blog post has an example.
https://blogs.sas.com/content/iml/2012/05/14/how-to-read-data-set-variables-into-sasiml-vectors.html

View solution in original post

6 REPLIES 6
Reeza
Super User
Y creates the vector there. You have a vector of -1, -2. You need to first load your data from a SAS data set into IML as a vector or matrix, since you only have one column a vector is fine. Then you can jump to the LY portion.

This blog post has an example.
https://blogs.sas.com/content/iml/2012/05/14/how-to-read-data-set-variables-into-sasiml-vectors.html
Cruise
Ammonite | Level 13
@Reeza, thanks a lot. Trying to understand the example. My actual data has about 1600 rows and 5 variables that all needed to be log transformed.
Cruise
Ammonite | Level 13

@Reeza 

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!
Reeza
Super User
Why are you using IML then? Why not keep everything in a data step?
Cruise
Ammonite | Level 13
Oops, yes, I should indeed 🙂
Reeza
Super User

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. 

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!
How to Concatenate Values

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.

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
  • 6 replies
  • 828 views
  • 2 likes
  • 2 in conversation