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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

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