BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
huhuhu
Obsidian | Level 7

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!

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Use the N function to count the number of non missing values.

 

If n(of var1-var3) >=1 then do;

View solution in original post

5 REPLIES 5
Reeza
Super User

Use the N function to count the number of non missing values.

 

If n(of var1-var3) >=1 then do;
huhuhu
Obsidian | Level 7

Thank you for your recommendation! but they are not consecutive variables. They locate at random place in a large dataset.

Astounding
PROC Star

If the variables you are concerned about are all numeric, you could use:

 

if n(of _numeric_) > 0 then do;

Reeza
Super User

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.




Tom
Super User Tom
Super User

It would help if you named your variables from the beginning to account for this need.

if n(of fruit_:) > 0 then flag='yes';

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1948 views
  • 1 like
  • 4 in conversation