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

Hello,

I am a beginner at SAS.

I have a data set with variable names look like this. aflag1 aflag2 bflag1 bflag2 cflag1 cflag2 

I want to find data where  *flag1 value is missing and *flag2 is not missing. 

For example if a line in data is aflag1 = '' and aflag2 <> '' then I want to print this line. 

I've been trying to strip flag first from variable names and try concatenate them back in data step. But I don't know if this will work. 

Please let me know if you have any approach to solve this problem. 

1 ACCEPTED SOLUTION

Accepted Solutions
andreas_lds
Jade | Level 19

You need two arrays: the first for the flag1-variables (names one), the other one for the flag2-variables (named two, then a loop for checking, the statement "output" to write the observation to the result-dataset and the statement "leave" to avoid duplication.

 

Here is untested code. Important all flag-variables need to either numeric or alphanumeric for this step to work.

data want;
  set have;

  array one aflag1 bflag1 cflag1;
  array two aflag2 bflag2 cflag2;

  do i = 1 to dim(one);
    if missing(one[i]) and not missing(two[i]) then do;
      output;
      leave;
    end;
  end;
run;

View solution in original post

2 REPLIES 2
andreas_lds
Jade | Level 19

You need two arrays: the first for the flag1-variables (names one), the other one for the flag2-variables (named two, then a loop for checking, the statement "output" to write the observation to the result-dataset and the statement "leave" to avoid duplication.

 

Here is untested code. Important all flag-variables need to either numeric or alphanumeric for this step to work.

data want;
  set have;

  array one aflag1 bflag1 cflag1;
  array two aflag2 bflag2 cflag2;

  do i = 1 to dim(one);
    if missing(one[i]) and not missing(two[i]) then do;
      output;
      leave;
    end;
  end;
run;
laiguanyu001
Fluorite | Level 6

Hi! Thanks for the quick response. I think this will work. But I'm also wondering, if now I only know that I have aflag1, bflag1, cflag1, can I use this information to find if aflag2, bflag2, cflag2 exists in the data?

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 2 replies
  • 710 views
  • 0 likes
  • 2 in conversation