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;

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!

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