BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Iona
Fluorite | Level 6

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!

1 ACCEPTED SOLUTION

Accepted Solutions
Iona
Fluorite | Level 6

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!

View solution in original post

4 REPLIES 4
jarg
Fluorite | Level 6

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

Iona
Fluorite | Level 6

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!

Astounding
PROC Star
The link you posted is solving a different problem: the minimum for each category.

Try (after sorting) :

data bla (drop = ....) ;
set sasuser.stress99 (obs=1) ;
run;
Iona
Fluorite | Level 6

Thank you, it's a very straightforward answer! 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 462 views
  • 0 likes
  • 3 in conversation