Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to add two variables together in SAS if one has missing values?

I would like to add two numerical variables together to create a new variable in SAS. However, if one of the variables is missing, SAS treats the entire observation is missing, even if the other variable has a value.

My code currently looks like this:

DATA FINAL.NEW_DATA;
SET FINAL.FULL_DATA;
FV_QTY = NUT_VEG_QTY + NUT_FRUITS_QTY; *new continuous variable;
RUN;

How can I get SAS to still include the observations from one variable, even if the other is missing?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Using the SUM Function instead. The Sum Function returns the sum of non-missing arguments.

DATA FINAL.NEW_DATA;
SET FINAL.FULL_DATA;
FV_QTY = sum(NUT_VEG_QTY, NUT_FRUITS_QTY);
RUN;
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading