Hi. this must be very basic question.
But I'm dealing with it for about... 12 hours. And I couldn't find the answer.
Data testtt;
Input group x1;
Cards;
1 1
1 10
1 30
2 100
2 1000
2 1200
3 30
3 43
3 77
;
Run;
In the data above, I'd like to make a new variable which shows the last value of each group. (Or the biggest number of each group is also fine)
So it should be the data like this:
Data Result;
Input group x1 last;
Cards;
1 1 30
1 10 30
1 30 30
2 100 1200
2 1000 1200
2 1200 1200
3 30 77
3 43 77
3 77 77
;
Run;
This must be the basic thing in SAS, but I couldn't find the way in SAS HELP or Google (or at least I don't know what to search...)
Thank you for the help in advance.
Data testtt;
Input group x1;
Cards;
1 1
1 10
1 30
2 100
2 1000
2 1200
3 30
3 43
3 77
;
Run;
proc sql;
create table want as
select *,max(x1) as max
from testtt
group by group;
quit;
biggest number
proc sql;
create table want as
select *,max(x1) as max
from have
group by group;
quit;
Data testtt;
Input group x1;
Cards;
1 1
1 10
1 30
2 100
2 1000
2 1200
3 30
3 43
3 77
;
Run;
proc sql;
create table want as
select *,max(x1) as max
from testtt
group by group;
quit;
biggest number
proc sql;
create table want as
select *,max(x1) as max
from have
group by group;
quit;
Thank you very much novinosrin!
Sql! That's what I should have learnt!
Have a nice day !
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.