BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
archita
Fluorite | Level 6

hi,

title'silver-level customers';
proc print data=silver;
run;

In this code, I am creating three datasets namely silver, gold and platinum based on the customer_id values. I also need to modify any four digit string in customer_id  by -15- instead of -00-, the searches are case insensitive.I am not getting the results please help. for e.g customer _id- platinum000-000-00-0010,Silver000-000-00-0024 etc. thanks in advance.

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Changing the value of CUSTOMER_ID after the observation has already been written is not going to have any impact.

Move the assignment statement before the IF statements that conditionally write the data.

 

Your IF statements are not going to write any of the observations that had the string '-00-' in them.

Do you want to test if the START of the value is Silver?

Use the colon modifier on the comparison operator.

customer_id=propcase(tranwrd(customer_id,'-00-','-15-'));
if customer_id =: 'Silver' then output silver;
if customer_id =: 'Gold' then output gold;
if customer_id =: 'Platinum' then output platinum;

View solution in original post

8 REPLIES 8
PaigeMiller
Diamond | Level 26

Show us a portion of the data before this change, and after.

--
Paige Miller
archita
Fluorite | Level 6

Hi,

Below is the input data

archita_0-1651248823076.png

I want it to be -15- in place of -00- , in case of all 4digit  string in customer_id.

PaigeMiller
Diamond | Level 26

UNTESTED CODE

 

data want;
    set have;
    customer_id=tranwrd(customer_id,'-00-,'-15-');
run;

 

The usual advice here is that we can't write code to test against screen captures of your data. The proper way to provide data from now on is as SAS data step code, which you can type yourself, or use these instructions. So from now on, please provide the data as requested.

--
Paige Miller
archita
Fluorite | Level 6

Hi,

The code provided is not working .

My code is;

data silver gold platinum;
set blib.customers_ex5;
customer_id=propcase(customer_id);
if customer_id = 'Silver' then output silver;
if customer_id = 'Gold' then output gold;
if customer_id = 'Platinum' then output platinum;
customer_id = tranwrd(customer_id,'-00-','-15-');
run;
title 'silver-level customers';
proc print data=silver;
run;
title'gold-level customers';
proc print data=silver;
run;
title'platinum-level customers';
proc print data=platinum;
run;

Tom
Super User Tom
Super User

Changing the value of CUSTOMER_ID after the observation has already been written is not going to have any impact.

Move the assignment statement before the IF statements that conditionally write the data.

 

Your IF statements are not going to write any of the observations that had the string '-00-' in them.

Do you want to test if the START of the value is Silver?

Use the colon modifier on the comparison operator.

customer_id=propcase(tranwrd(customer_id,'-00-','-15-'));
if customer_id =: 'Silver' then output silver;
if customer_id =: 'Gold' then output gold;
if customer_id =: 'Platinum' then output platinum;
archita
Fluorite | Level 6

Thank you, working now.

PaigeMiller
Diamond | Level 26

Hello @archita 

 

As requested above, it is not sufficient to say it is not working, and provide no other details. If there are errors in the log, then SHOW US the entire log for the step which isn't working (instructions for providing the log already provided, please follow them). If the output is wrong, then SHOW US what output you get, and what you want to get.

--
Paige Miller
archita
Fluorite | Level 6

Thanks , point noted.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 8 replies
  • 1299 views
  • 1 like
  • 3 in conversation