BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ilikesas
Barite | Level 11

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!

1 ACCEPTED SOLUTION

Accepted Solutions
stat_sas
Ammonite | Level 13

data want;

set have;

if pctshares=. then pctshares=100-pctstock;

if pctstock=. then pctstock=100-pctshares;

run;

View solution in original post

2 REPLIES 2
stat_sas
Ammonite | Level 13

data want;

set have;

if pctshares=. then pctshares=100-pctstock;

if pctstock=. then pctstock=100-pctshares;

run;

Patrick
Opal | Level 21

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;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

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