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

Hello team,

Can any one explain this?

 

When an observation is the first in a by group, sas set the value of first.variable to 1. This happens when the value of the variable changed from the previous observation.

 

b. For all other observations in the by group. they value of first.variable is 0.

 

Does section b mean that all other observations in the same group or other groups?

 

Please elaborate this?

Regards,

blueblue

 

Blue Blue
1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Try it and see.

proc sort data=sashelp.class out=class;
  by sex;
run;

data test;
  set class;
  by sex;
  first_sex = first.sex;
  last_sex = last.sex;
run;

proc print;
  var first_sex last_sex sex name;
run;

View solution in original post

2 REPLIES 2
Tom
Super User Tom
Super User

Try it and see.

proc sort data=sashelp.class out=class;
  by sex;
run;

data test;
  set class;
  by sex;
  first_sex = first.sex;
  last_sex = last.sex;
run;

proc print;
  var first_sex last_sex sex name;
run;
ChrisNZ
Tourmaline | Level 20

> When an observation is the first in a by group, sas set the value of first.variable to 1. ... For all other observations in the by group. they value of first.variable is 0.

 

That's how this is supposed to work. Your question is nuclear.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 781 views
  • 2 likes
  • 3 in conversation