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;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.