SAS Data Integration Studio, DataFlux Data Management Studio, SAS/ACCESS, SAS Data Loader for Hadoop and others

How to replace values of set of variables

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 14
Accepted Solution

How to replace values of set of variables

[ Edited ]

Hi guys,

Can someone help me to change the dataset according to the following?

 

 

Thank you.

 

 

Khalid

Slide1.JPG

 


Accepted Solutions
Solution
‎04-11-2017 12:31 PM
PROC Star
Posts: 7,473

Re: How to replace values of set of variables

Nothing wrong with grouping them together. e.g.:

 

data want;
  set have;
  if v1=v2=v3=8 then call missing(of v1-v3);
run;

Art, CEO, AnalystFinder.com

 

View solution in original post


All Replies
Super User
Posts: 19,800

Re: How to replace values of set of variables

Posted in reply to khalidamin

Whats the rule? All 8s or all the same value? What if you have two the same value and one is missing.

 

You can use MIN/MAX logic - if the min=max then the values are the same and you can use CALL MISSING to set variables to missing. 

 

Useful functions:

 

N - returns number of non missing

NMISS - returns the number of missing

MIN - returns minimum value

MAX - returns max value

CALL MISSING() - sets variables designated to as missing - doesn't matter if they're character or numeric.

 

 

PS. Post data not in images but at least as text, ideally as a data step. We can't write code based on an image so that would mean typing out your dataset. 

 

 

 

PROC Star
Posts: 7,473

Re: How to replace values of set of variables

or just use something like:

 

data want;
  set have;
  array vars(*) v1-v3;
  if v1=v2=v3 then call missing(of vars(*));
run;

Art, CEO, AnalystFinder.com

 

Occasional Contributor
Posts: 14

Re: How to replace values of set of variables

I want 'if v1=v2=v3=8 THEN 'v1=v2=v3=missing'.
Occasional Contributor
Posts: 14

Re: How to replace values of set of variables

Thank you for your comments. I want to consider 8s as missing when they are in all variables. For example, if v1=v2=v3=8, then

v1=v2=v3=missing. @Reeza

Super User
Posts: 19,800

Re: How to replace values of set of variables

Posted in reply to khalidamin

If v1=8 and v2=8 and v3 =8 then call missing(v1, v2, v3);

Solution
‎04-11-2017 12:31 PM
PROC Star
Posts: 7,473

Re: How to replace values of set of variables

Nothing wrong with grouping them together. e.g.:

 

data want;
  set have;
  if v1=v2=v3=8 then call missing(of v1-v3);
run;

Art, CEO, AnalystFinder.com

 

Occasional Contributor
Posts: 14

Re: How to replace values of set of variables

Awesome! Thank you @art297 Smiley Happy
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 7 replies
  • 1239 views
  • 3 likes
  • 3 in conversation