I have the following issue. I'm trying to have the following result:
If &&&&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.
Can you show your data and the result you are after. I'm sorry but I'm to old for &&&&:smileyshocked:
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.
Actually missing underscore ._ is smallest but we know what you mean.
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
Example:
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?
Is it this?
Argh.
So my boss was right, you actually need a proc summary ...
Is there no other way to deal with that?
Maybe that's why he's the boss.
You can do it the hard way.
Dear sir,
Thanks for your answer.
You gave me my morning smile.
And true , this is the why he is the boss
Andy
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;
Xia Keshan
He is old school
But I like SQL.
Thanks Xia.
When is SQL not old school? Over 20 years as PROC SQL and SQL has been around much longer than that.
Hi Ballardw,
I though that . was meaning 0. This is why I've put the dot.
Thanks,
Andy
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 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.