BookmarkSubscribeRSS Feed
SAS_taozi
Calcite | Level 5

Hi All, I am dealing with a long table (group data) of purchase records. I want to know for each customer, whether they have the exactly same purchase price every time of their visits. Let's say my goal is to test whether the purchase price is $10 for each customer each time they visit.. Below is an example:

 

ID Price

1   3

1   4 

1   3

2   5

2   5

 

And what I want is ...

 

ID Price  Same_Price_equal_to_10

1   3       0

1   4       0

1   3       0

2   5       0

2   5       0

3   10     1

3   10     1

3   10     1

3   10     1

Note that if this customer has persistent purchase price of 5... is not nothing I wanted. I want to set a target for the purchase price and only if this targeted purchase price is consistent all the time would be something I wanted... Anyone could help me with that? Very much appreciated!

1 REPLY 1
PaigeMiller
Diamond | Level 26
proc summary data=have nway;
     class id;
     var price;
    output out=flag min=min max=max;
run;
data want;
    merge have flag;
    by id;
    if min=10 and max=10 then same_price_equal_to_10=1;
    else same_price_equal_to_10=0;
    drop min max;
run;
--
Paige Miller

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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
  • 1 reply
  • 452 views
  • 1 like
  • 2 in conversation