DATA Step, Macro, Functions and more

How to create values for groups??

Reply
New Contributor
Posts: 2

How to create values for groups??

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;

 

Trusted Advisor
Posts: 1,848

Re: How to create values for groups??

Posted in reply to isabeljason

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

data want;

 set have;

  by Index;

       if last.index;

run;

 

New Contributor
Posts: 2

Re: How to create values for groups??

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

 

Valued Guide
Posts: 624

Re: How to create values for groups??

Posted in reply to isabeljason

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;

 

Super User
Posts: 13,889

Re: How to create values for groups??

Posted in reply to isabeljason

@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".

Ask a Question
Discussion stats
  • 4 replies
  • 97 views
  • 0 likes
  • 4 in conversation