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

filling empty variables conditional on non empty variables

Accepted Solution Solved
Reply
Super Contributor
Posts: 441
Accepted Solution

filling empty variables conditional on non empty variables

Hi,

suppose i have the following table:

obspct sharespct stock
13070
240
355
4

The sum of the 2 pct shares and pct stock should equal to 100 for every observation. In the cases when one of the two is missing, I need to find the other one by subtracting the non missing value from 100. In the cases when both are present or missing leave as is.

So the desired table is the following:

obspct sharespct stock
13070
24060
34555
4

Thank you!


Accepted Solutions
Solution
‎05-10-2015 04:05 PM
Trusted Advisor
Posts: 1,228

Re: filling empty variables conditional on non empty variables

data want;

set have;

if pctshares=. then pctshares=100-pctstock;

if pctstock=. then pctstock=100-pctshares;

run;

View solution in original post


All Replies
Solution
‎05-10-2015 04:05 PM
Trusted Advisor
Posts: 1,228

Re: filling empty variables conditional on non empty variables

data want;

set have;

if pctshares=. then pctshares=100-pctstock;

if pctstock=. then pctstock=100-pctshares;

run;

Respected Advisor
Posts: 4,173

Re: filling empty variables conditional on non empty variables

Amending the code from stat@sas to only calculate values "when one of the two is missing".

data want;

  set have;

  if cmiss(pctshares,pctstock)=1 then

    do;

      if pctshares=. then pctshares=100-pctstock;

      else pctstock=100-pctshares;

    end;

run;

🔒 This topic is solved and locked.

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

Discussion stats
  • 2 replies
  • 273 views
  • 3 likes
  • 3 in conversation