BookmarkSubscribeRSS Feed
Alessandra_005
Calcite | Level 5

Hi everybody!

 

In my dataset, for every customer I have the corresponding column with "Active" or "Passive"

How can I convert them in Active = 0 and Passive = 1 on SAS

 

Thank you in advance

 

 

4 REPLIES 4
RW9
Diamond | Level 26 RW9
Diamond | Level 26

So you have a character column and want it displayed as 1 or 0, then a proc format and apply that to your column would be simplest.  Alternatively create new column and rename:

data want;
  set have;
  num_col=ifn(char_col="Active",1,0);
run;

Its useful to post test data in the form of a datastep and what you want the output to look like otherwise we are just guessing.

Alessandra_005
Calcite | Level 5

At first, thank you from the prompt reply.

My dataset look like

 

curtomer          Status

1                       Active

2                       Passive

3                       Passive

4                       Passive

5                       Active

6                       Active

 

ect. so I want Passive and Active to be transformed in 0 and 1

 

thank you

 

RW9
Diamond | Level 26 RW9
Diamond | Level 26

What do you mean by transformed?  If you want to replace the text "Active" with the text "1" then:

var=tranwrd(var,"Active","1");

But if you want a numeric variable then you have to rename, create a new one:

data want;
  set have (rename=(var=old_var));
  var=ifn(old_var="Active",1,0);
run;
Kurt_Bremser
Super User
data have;
input customer status $;
cards;
1 Active
2 Passive
3 Passive
4 Passive
5 Active
6 Active
;
run;

proc format library=work;
invalue stat
  "Active" = 1
  "Passive" = 0
  other = -1
;
value $stat
  "Active" = '1'
  "Passive" = '0'
  other = '.'
;
run;

data want;
set have;
stat_num = input(status,stat.);
stat_num2 = ifn(status="Active",1,0);
format status $stat.;
run;

Note how I presented your example data in a form that allows for easy recreation through a simple copy/paste and run.

You see three possible methods for achieving your objective, the last by not changing/setting any value at all, but by applying a display format.

Which method you use depends on the format in which you want to have the 0s and 1s.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 4 replies
  • 933 views
  • 1 like
  • 3 in conversation