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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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
  • 762 views
  • 3 likes
  • 3 in conversation