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.
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;
Show us a portion of the data before this change, and after.
Hi,
Below is the input data
I want it to be -15- in place of -00- , in case of all 4digit string in customer_id.
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.
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;
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;
Thank you, working now.
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.
Thanks , point noted.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.