DATA Step, Macro, Functions and more

Set value based on other value

Accepted Solution Solved
Reply
Contributor
Posts: 33
Accepted Solution

Set value based on other value

[ Edited ]

I want to give the value for some specific rows. I think showing it by example would be better. I have following datasheet;

 Date                 Value
01/01/2001          10
02/01/2001          20
03/01/2001          35
04/01/2001          15
05/01/2001          25
06/01/2001          35
07/01/2001          20
08/01/2001          45
09/01/2001          35

My result should be:

 Date                 Value    Spec.Value
 01/01/2001          10        1
 02/01/2001          20        1
 03/01/2001          35        1
 04/01/2001          15        2
 05/01/2001          25        2
 06/01/2001          35        2
 07/01/2001          20        3
 08/01/2001          45        3
 09/01/2001          35        3

As you can see, my condition value is 35. I have three 35. I need to group my date by using this condition value.


Accepted Solutions
Solution
‎01-12-2017 08:36 AM
Super User
Super User
Posts: 7,401

Re: SAS_Specific Value for rows

I haven't run this, as not typing in that test data.  For future reference post test data in the form of a datastep:

data want;
  set have;
  retain spec_value 1;
  output;
  if value=35 then spec_value=sum(spec_value,1);
run;

View solution in original post


All Replies
Solution
‎01-12-2017 08:36 AM
Super User
Super User
Posts: 7,401

Re: SAS_Specific Value for rows

I haven't run this, as not typing in that test data.  For future reference post test data in the form of a datastep:

data want;
  set have;
  retain spec_value 1;
  output;
  if value=35 then spec_value=sum(spec_value,1);
run;
Contributor
Posts: 33

Re: SAS_Specific Value for rows

Many thank. It worksSmiley Happy
Super User
Posts: 17,819

Re: SAS_Specific Value for rows

@Khaladdin Please mark the question answered. 

Contributor
Posts: 33

Re: SAS_Specific Value for rows

I accept the answer as a right answer. Is that enough? @Reeza
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 156 views
  • 1 like
  • 3 in conversation