Dear all,
I have many categories of variables and each of category include a lot of variables. I would like to create a statement that for each individual observation, if there is at least one variable has non missing value, then we can use this observation. Now I only know the statement like below:
if apple ne . or banana ne . or grape ne. then flag='yes';
However, since I have tons of variables in each category, it will be very time consuming to type them individually. I'm wondering if there is an efficient way to do it.
I appreciate any thoughts and recommendations.
Thank you!
Use the N function to count the number of non missing values.
If n(of var1-var3) >=1 then do;
Use the N function to count the number of non missing values.
If n(of var1-var3) >=1 then do;
Thank you for your recommendation! but they are not consecutive variables. They locate at random place in a large dataset.
If the variables you are concerned about are all numeric, you could use:
if n(of _numeric_) > 0 then do;
If you don't have a naming convention or they're not placed sequentially then unfortunately you're stuck listing them all out.
@huhuhu wrote:
Thank you for your recommendation! but they are not consecutive variables. They locate at random place in a large dataset.
It would help if you named your variables from the beginning to account for this need.
if n(of fruit_:) > 0 then flag='yes';
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.