BookmarkSubscribeRSS Feed
isabeljason
Calcite | Level 5

I have an informational index with the initial 3 sections. How would I get the fourth sections in view of the pointers? For instance, for the file, when the pointer =1, the esteem is 21, so I put 21 is the last esteems in all lines for file 1. Could anyone suggest the procedure to Base SAS.

 

data test;
input Index Indicator value FinalValue;
datalines;

1 0  5   21
1 1  21  21
2 1  0   0
3 0  4   0
3 1  7   7
3 0  8   7
3 0  2   7
4 1  1   1
4 0  4   1
;
run;

 

4 REPLIES 4
Shmuel
Garnet | Level 18

Assuming data is sorted and you want the last given FinalValue then:

data want;

 set have;

  by Index;

       if last.index;

run;

 

isabeljason
Calcite | Level 5

Thanks for the reply. Will try and let you know the details.

 

andreas_lds
Jade | Level 19

Not sure, if i understand what you need to do.

  • You want to create the variable FinalValue.
  • FinalValue is set per index to Value of the observation having Indicator = 1

Right? If yes: why is FinalValue=0 in line 4? It should be 7.

3 0  4   0

 

Is there exactly one observation with having Indicator = 1 for each Index? If yes, try:

 

data have;
input Index Indicator value;
datalines;

1 0 5
1 1 21
2 1 0
3 0 4
3 1 7
3 0 8
3 0 2
4 1 1
4 0 4
;
run;

data want;
   merge have have(rename=(Indicator=Flag value=FinalValue) where=(Flag = 1));
   by Index;

   drop Flag;
run;

 

ballardw
Super User

@isabeljason wrote:

I have an informational index with the initial 3 sections. How would I get the fourth sections in view of the pointers? For instance, for the file, when the pointer =1, the esteem is 21, so I put 21 is the last esteems in all lines for file 1. Could anyone suggest the procedure to Base SAS.

 

data test;
input Index Indicator value FinalValue;
datalines;

1 0  5   21
1 1  21  21
2 1  0   0
3 0  4   0
3 1  7   7
3 0  8   7
3 0  2   7
4 1  1   1
4 0  4   1
;
run;

 


Your variables are Index Indicator value FinalValue but you address your values as esteem, "section" and possibly "pointers". It will help everyone to address things in terms of the variable names, or change the variable names to reflect the words you use. Also "initial 3 sections" isn't clear unless you mean "first three values for the variable Index".

SAS Innovate 2025: Call for Content

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 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 4 replies
  • 945 views
  • 0 likes
  • 4 in conversation