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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

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