Replacing observations

Reply
New Contributor
Posts: 3

Replacing observations

Hii...

Can anyone tell me how to replace the observations of a particular variable in a data set.?

Frequent Contributor
Posts: 117

Re: Replacing observations

i think  merge / update  will work.

Frequent Contributor
Posts: 117

Re: Replacing observations

or if you can provide sample data and output (how you want) , that could be helpful in answering your question.

New Contributor
Posts: 3

Re: Replacing observations

Hello Vish,

The question is "Create a new data and transform the values of 5 variables(weight, calories, Protein, fat, Satfat). Variables containing Value = 11 will be replaced by the Value of 3 ."

The solution I had tried is

data bittu.junkfood123;

set  bittu.junkfood;

WEIGHT = 3;

replace all var {WEIGHT} where (WEIGHT==11);

run;

Untitled.png

Iam getting error when I execute my code.

New Contributor
Posts: 3

Re: Replacing observations

Hello vish,

The Problem that I had is "Create a new data and transform the values of 5 variables(weight, calories, Protein, fat, Satfat). Variables containing Value = 11 will be replaced by the Value of 3 ."

The code that I tried is

data bittu.junkfood123;

set  bittu.junkfood;

WEIGHT = 3;

replace all var {WEIGHT} where (WEIGHT==11);

run;

but I am getting error when I execute this...

Untitled.png

Frequent Contributor
Posts: 144

Re: Replacing observations

I will do something like

data bittu.junkfood123;

set  bittu.junkfood;

IF WEIGHT = 11 THEN WEIGHT=3;

run;

Also if you want to do the same for this 5 variables you could use an array

data bittu.junkfood123;

set  bittu.junkfood;

array vars{*} weight  calories  Protein fat Satfat;

do over vars;

if vars=11 then vars=3;

end;

run;

Ask a Question
Discussion stats
  • 5 replies
  • 262 views
  • 1 like
  • 3 in conversation