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

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