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

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.

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20
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;

View solution in original post

2 REPLIES 2
novinosrin
Tourmaline | Level 20
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;

MonoLight
Obsidian | Level 7

Thank you very much novinosrin!

Sql! That's what I should have learnt!

 

Have a nice day !

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
  • 2 replies
  • 2515 views
  • 0 likes
  • 2 in conversation