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.

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
  • 2 replies
  • 352 views
  • 2 likes
  • 3 in conversation