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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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