DATA Step, Macro, Functions and more

Formatting value

Reply
Occasional Contributor
Posts: 5

Formatting value

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'
PROC Star
Posts: 547

Re: Formatting value

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

Occasional Contributor
Posts: 5

Re: Formatting value

Yes
Occasional Contributor
Posts: 5

Re: Formatting value

I have lot of values like d1, e1 etc
Super User
Posts: 17,749

Re: Formatting value

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.

 

 

PROC Star
Posts: 1,555

Re: Formatting value

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;

 

 

Occasional Contributor
Posts: 5

Re: Formatting value

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
Occasional Contributor
Posts: 5

Re: Formatting value

I have different values for different observation
PROC Star
Posts: 1,555

Re: Formatting value

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.

Ask a Question
Discussion stats
  • 8 replies
  • 177 views
  • 0 likes
  • 4 in conversation