BookmarkSubscribeRSS Feed
rgururaj1980
Calcite | Level 5
Hello, please help me in the below issue for formatting in sas
I have a file containing variable Result which has value of
(C1='y' and b1='N' and a1='y') like that
I want to replace a1,b1,c1 etc with text. Like customer1='y' and customerb ='n'
8 REPLIES 8
PeterClemmensen
Tourmaline | Level 20

Just to be clear, you have a character variable called Result which contains a string like "(C1='y' and b1='N' and a1='y')" ?

rgururaj1980
Calcite | Level 5
Yes
rgururaj1980
Calcite | Level 5
I have lot of values like d1, e1 etc
Reeza
Super User

http://www2.sas.com/proceedings/sugi30/001-30.pdf

 

This paper walks through how to recode variables using a format. It's well written and clear.

 

Another standard way to recode is IF/THEN statements.

 

 

ChrisNZ
Tourmaline | Level 20

C1 is your variable name, so you want to rename your variables.

You'll need something like:

data WANT;
  set HAVE(rename=(C1=CUSTOMER1 
                   B1=CUSTOMERB)
          );
  RESULT=(CUSTOMER1 ='Y' & CUSTOMERB='N' );
run;

 

 

rgururaj1980
Calcite | Level 5
Formula is my variable name and it contains "c1=yes,b1=no, z3=yes" . It has value like this . I want to change c1 b1 e1 with text
rgururaj1980
Calcite | Level 5
I have different values for different observation
ChrisNZ
Tourmaline | Level 20

Your explanations were not clear. Always show : this is what I have & this is what I want.

 

Like this?

data WANT;
  length RESULT $1000;
  RESULT= "(C1='y' and b1='N' and a1='y')" ;
  RESULT=transtrn(RESULT,'C1=','CUSTOMER1=');
  RESULT=transtrn(RESULT,'b1=','CUSTOMERB=');
  putlog RESULT=;
run;

 

RESULT=(CUSTOMER1='y' and CUSTOMERB='N' and a1='y')

 

Don't forget to make your string longer.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 8 replies
  • 2283 views
  • 0 likes
  • 4 in conversation