Help using Base SAS procedures

Flag Missing Values in a Dataset

Accepted Solution Solved
Reply
Contributor
Posts: 64
Accepted Solution

Flag Missing Values in a Dataset

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.


Accepted Solutions
Solution
‎07-12-2015 07:06 AM
Super User
Posts: 9,671

Re: Flag Missing Values in a Dataset

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


All Replies
Solution
‎07-12-2015 07:06 AM
Super User
Posts: 9,671

Re: Flag Missing Values in a Dataset

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

Contributor
Posts: 64

Re: Flag Missing Values in a Dataset

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,

Contributor
Posts: 64

Re: Flag Missing Values in a Dataset

Hi Xia,

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

Thanks,

Super User
Posts: 9,671

Re: Flag Missing Values in a Dataset

Yes. List the variables you need at here :

array x{*} $ a b  c d ;

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 298 views
  • 0 likes
  • 2 in conversation