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

Hello All,

I have a dataset with groups of variables obtained from different files. The structure is as follows (note: variable names might vary):

Country_File1     Country_File2     Country_File3     Zip_File1     Zip_File2     Name_File1     Name_File2    

Norway               India                                            56698                              Andrew          Justin

Sweden            Russia               Denmark                                 8JH87                                 John

I need to create a new flag variable in the file based on the missing values of the above variables as follows:

     Missing_Group

Country_File3, Zip_File2

Name_File1,Zip_FIle1

I know the result can be obtained using several (need about 25) IF THEN statements and CATX, but was looking for a simpler way.

Thanks for your help.

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

Why not ARRAY ?

data have;
input (Country_File1     Country_File2     Country_File3     Zip_File1     Zip_File2     Name_File1     Name_File2) ($);
cards; 
Norway               India                  .                          56698       .                       Andrew          Justin
Sweden            Russia               Denmark                .                 8JH87             .                    John
;
run;
data want;
 set have;
 length Missing_Group $ 400;
 array x{*} $ _character_;
 do i=1 to dim(x);
  if missing(x{i}) then Missing_Group=catx(',',Missing_Group,vname(x{i}));
 end;
 drop i;
run;
  

Xia Keshan

View solution in original post

4 REPLIES 4
Ksharp
Super User

Why not ARRAY ?

data have;
input (Country_File1     Country_File2     Country_File3     Zip_File1     Zip_File2     Name_File1     Name_File2) ($);
cards; 
Norway               India                  .                          56698       .                       Andrew          Justin
Sweden            Russia               Denmark                .                 8JH87             .                    John
;
run;
data want;
 set have;
 length Missing_Group $ 400;
 array x{*} $ _character_;
 do i=1 to dim(x);
  if missing(x{i}) then Missing_Group=catx(',',Missing_Group,vname(x{i}));
 end;
 drop i;
run;
  

Xia Keshan

sasmaverick
Obsidian | Level 7

Hi Xia,

Thank you for the logic. It seems to work. But the dataset I have has about 200 other variables. I just want to consider the ones I showed her for flags. Wouldn't the array test for missing values of all variables? How do I limit it to testing only the few variables?

Thanks again,

sasmaverick
Obsidian | Level 7

Hi Xia,

Got it, should I just name the variables I want instead of _CHARACTER_ ?

Thanks,

Ksharp
Super User

Yes. List the variables you need at here :

array x{*} $ a b  c d ;

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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