Hi,
suppose i have the following table:
obs | pct shares | pct stock |
---|---|---|
1 | 30 | 70 |
2 | 40 | |
3 | 55 | |
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:
obs | pct shares | pct stock |
---|---|---|
1 | 30 | 70 |
2 | 40 | 60 |
3 | 45 | 55 |
4 |
Thank you!
data want;
set have;
if pctshares=. then pctshares=100-pctstock;
if pctstock=. then pctstock=100-pctshares;
run;
data want;
set have;
if pctshares=. then pctshares=100-pctstock;
if pctstock=. then pctstock=100-pctshares;
run;
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;
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.
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.