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

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 680 views
  • 1 like
  • 2 in conversation