SAS - Keeping only observations with all variables

泄露秘密 提交于 2019-12-12 04:55:48

问题


I have a dataset of membership information, and I want to keep only the people who have been continuously enrolled for the entire year. There are 12 variables for each person, one for each month of the year with how many days during that month they were enrolled. Is there a way to make a subset of the data for just those with a value >1 for each of the month variables?

Thanks!


回答1:


SAS has various summary functions that might well be what you're looking for. See min() (minimum) in particular, as it will allow you to find the minimum of several variables. You may also want to consider nmiss() (number of missing values) and n() (number of non-missing values) if you have to deal with missing values in your data.

Summary functions can be passed lists of variables like this (in a data step):

minimum = min(var1, var2, var3);

However, that can become long winded if you need to use a lot of variables. Fortunately, SAS provides several ways to reference lists of variables to make things neater. You can read about these variable lists here. To use them in a summary function use the of qualifier:

minimum = min(of var1-var12);
maximum = max(of var:);
blanks = nmiss(of _NUMERIC_);

Finally you will want to use your new found data to decide whether what data to include. To do this in a data step look at the output statement (user guide):

if min(of var:) > 1 then output;

Or if you feel like learning a bit more about SAS's syntax you could try using an implicit output by reading through the last link.

In general it's preferred to ask specific questions and show your current work on SO, and I'd advise using google to answer your basic questions while you're learning the fundamentals. There is plenty of great documentation available to help you out there.



来源:https://stackoverflow.com/questions/28614514/sas-keeping-only-observations-with-all-variables

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!