05-29-2014 01:39 PM
I have the following issue. I'm trying to have the following result:
&&&&var&&pays&l.._&i.._t&j is negative then
varnum_&i._&j=log(min(&&&&var&&pays&l.._&i.._t&j)) e.g. choose the minimum observation for that variable.
However, as you can see, I'm dealing with variables rather than only observations.
I'm clueless on that one.
All the code is below.
data afr_test2 ; set afr_test1 ; %do j=0 %to 5 ;%do i=1 %to &&&&nvar&&pays&l ; format varnum_&i._&j 10.3 ; /*2eme modele: */ /* varnum_&i._&j=&&&&var&&pays&l.._&i.._t&j;*/ if &&&&var&&pays&l.._&i.._t&j < . then do ; varnum_&i._&j=log(min(&&&&var&&pays&l.._&i.._t&j)); else varnum_&i._&j=log(&&&&var&&pays&l.._&i.._t&j); end; if varnum_&i._&j eq . then varnum_&i._&j=0; %end ; %end; run ;
I was thinking of using a proc sql and create a table to get all the minimum observation for that variables.
Something like that
proc sql: create table toto as select min(val) from table_name;
But how would I get the variable name, side by side with the minimum from that specific variable?
Thanks for any insight you can provide.
05-29-2014 03:28 PM
f &&&&var&&pays&l.._&i.._t&j < . won't ever be true . (missing is smallest value) you want
f &&&&var&&pays&l.._&i.._t&j < 0 to indicate negative.
05-29-2014 04:01 PM
Actually missing underscore ._ is smallest but we know what you mean.
05-29-2014 04:42 PM
Hi Data Null,
The ._ means the smallest record?
I'm trying to do the following:
For each records that is negative, give me the smallest value plus the actual value of the observation for that variable
var1 var2 var3
. . .
1 3 5
-2 -2 -1
3 5 1
For var1, I would have -2 plus 1. For var2, I would have -2 plus 3 etc...
Do you want me to clean the code?
05-29-2014 04:54 PM
Is it this?
05-29-2014 04:58 PM
So my boss was right, you actually need a proc summary ...
Is there no other way to deal with that?
05-29-2014 06:48 PM
Maybe that's why he's the boss.
You can do it the hard way.
05-30-2014 03:03 AM
Thanks for your answer.
You gave me my morning smile.
And true , this is the why he is the boss
05-30-2014 09:44 AM
If your boss know or like SQL ?
data have; input var1-var3; cards; . . . 1 3 5 -2 -2 -1 3 5 1 ;;;; run; proc sql; create table want as select *,var1+(select min(var1) from have) as new1, var2+(select min(var2) from have) as new2, var3+(select min(var3) from have) as new3 from have; quit;