BookmarkSubscribeRSS Feed
eer_seer
Obsidian | Level 7

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!

 

4 REPLIES 4
Tom
Super User Tom
Super User

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;
sbxkoenk
SAS Super FREQ

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

sbxkoenk
SAS Super FREQ

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

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 2274 views
  • 0 likes
  • 4 in conversation