I want to create a variable that is the minimum value of a variable in my dataset.
How would I create a variable that refers to the MIN value of a single column? How would a get a variable say "min1" to report back the 50? I assume it has to do with arrays but I can't quite put my finger on it and every time I try just the "MIN" function I get an error of not enough arguments.
data work.test;
input value1;
datalines;
100
200
300
250
50
400
;
run;
Thanks!
You need to process the whole dataset to get the minimum over all of the observations.
proc summary data=test ;
var value1;
output out=want min=min1;
run;
Hello,
You would use an array on the transposed dataset (your values in the columns and not in the rows).
You can indeed use the min function on an array of elements.
With your values in the rows (and in one column) I would proceed as indicated by @Tom .
If you absolutely want to use the min data step function, you can do this;
data work.test;
input value1;
datalines;
100
200
300
250
50
400
;
run;
data _NULL_;
set work.test end=last;
file print;
retain minv;
if _N_=1 then minv=value1;
minv=min(minv,value1);
if last then put minv;
run;
/* end of program */
Koen
To be complete, I will add this extra possibility:
proc transpose data=work.test out=work.test_trp;
var value1;
run;
data _NULL_;
set work.test_trp;
file print;
min_value=min(of _NUMERIC_);
put min_value=;
run;
/* end of program */
Koen
proc sql;
select min(value1) from test;
quit;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.