Hi everyone!
I'm using the SAS sample data set called stress99.
data sasuser.stress99; input ID $ 1-4 Name $ 7-18 RestHR 25-26 MaxHR 32-34 RecHR 39-41 TimeMin 48-49 TimeSec 57-58 Tolerance $ 65 Year 70-73; datalines; 2501 Bonaventure, T 78 177 139 11 13 I 1999 2544 Jones, M 79 187 136 12 26 N 1999 2552 Reberson, P 69 158 139 15 41 D 1999 2568 Eberhardt, S 72 182 122 16 49 N 1999 2571 Nunnelly, A 65 181 141 15 2 I 1999 2578 Cameron, L 75 158 108 14 27 I 1999 2579 Underwood, K 72 165 127 13 19 S 1999 2588 Ivan, H 70 182 126 15 41 N 1999 2595 Warren, C 77 170 136 12 10 S 1999 ;
Now what I would like to do is to create a data set that holds only the smallest value for TimeMin, which would be TimeMin=11.
I tried:
proc sort data = sasuser.stress99; by timemin; run;
data bla (drop = resthr maxhr rechr tolerance timesec year);
set sasuser.stress99;
by timemin;
first_time= first.timemin;
if first.timemin;
run;
But what it will give me is the first UNIQUE value for TimeMin. Where am I going wrong? I found this solution and I don't see why it works in their example but not in mine.
Thank you!
Thank you for your answer! I was able to use it. I wasn't too clear in my question but I wanted to keep the whole observation with the minimum timemin.
I used your solution to write
proc sql;
create table subset as
select ID, Name, min(timemin) as mintime from stress;
I never used proc SQL so while it's straightforward it's still new to me.
Thanks!
the way that the unprinted variable first.[var] works is that it will resolve to 1 for the first observation with a distinct value - so if you are conditionally setting a table by saying if first.timein it will keep the first observation with a distinct value (this is also what's happening in the other solution you linked.)
if you're after the minimum value in the whole dataset, using i would recommend turning it into a macro;
proc sql noprint; select min(timemin) into: mintimemin from stress99;
%put &mintimemin.;
this will allow you to run calculations off this value
Thank you for your answer! I was able to use it. I wasn't too clear in my question but I wanted to keep the whole observation with the minimum timemin.
I used your solution to write
proc sql;
create table subset as
select ID, Name, min(timemin) as mintime from stress;
I never used proc SQL so while it's straightforward it's still new to me.
Thanks!
Thank you, it's a very straightforward answer!
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 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.