BookmarkSubscribeRSS Feed
PreethamReddy
Calcite | Level 5

Hii...

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

5 REPLIES 5
Vish33
Lapis Lazuli | Level 10

i think  merge / update  will work.

Vish33
Lapis Lazuli | Level 10

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

PreethamReddy
Calcite | Level 5

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.

PreethamReddy
Calcite | Level 5

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

arodriguez
Lapis Lazuli | Level 10

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;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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