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

sas-innovate-2024.png

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.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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