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';
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.
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.