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.
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;
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;
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 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.