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

Good morning,

Probably I am missing something very simple, but I am just a beginner in SAS...

I am trying to find a solution, how to add a variable with min (x_min) of a given variable (x) per observation (id).

My dataset looks like:

id x     y

1 10   1

1 20   2

1 30   3

2 100 10

2 200  20

...

 

and what I need is:

id x     min_x   y

1 10    10        1

1 20    10        2

1 30    10        3

2 100  100     10

2 200   100     20

...

 

Would you be so kind to help me?

Thank you in advance!

Piotr Lewczuk

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Super User
data have;
input id x y;
datalines;
1 10   1
1 20   2
1 30   3
2 100 10
2 200  20
;

proc sql;
   create table want as
   select id,
          x,
          min(x) as min_x,
          y
   from have
   group by id;
quit;

View solution in original post

2 REPLIES 2
PeterClemmensen
Super User
data have;
input id x y;
datalines;
1 10   1
1 20   2
1 30   3
2 100 10
2 200  20
;

proc sql;
   create table want as
   select id,
          x,
          min(x) as min_x,
          y
   from have
   group by id;
quit;
PiotrLewczuk
Fluorite | Level 6

Thank you so much! You really helped me.

Take care,

Piotr

SAS INNOVATE 2024

innovate-wordmarks-white-horiz.png

SAS is headed back to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team.

Interested in speaking? Content from our attendees is one of the reasons that makes SAS Innovate such a special event!

Submit your idea!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

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

View all other training opportunities.

Discussion stats
  • 2 replies
  • 276 views
  • 0 likes
  • 2 in conversation