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

Hello

How can i get the name of all missing variables raw by raw. thx

 

example

 

var1   var2   var3   var4    deriver_var  

.          1        2        3       var1

2         .        .          4       var2 var3

.          .        4         .       var1 var2 var4

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21
data want;
  set have;
  length deriver_var $50;
  array vars(*) var1-var4;
  do _n_=1 to dim(vars);
    if missing(vars(_n_)) then do;
      deriver_var=catx(' ',deriver_var,vname(vars(_n_)));
    end;
  end;
run;

Art, CEO, AnalystFinder.com

 

View solution in original post

7 REPLIES 7
art297
Opal | Level 21
data want;
  set have;
  length deriver_var $50;
  array vars(*) var1-var4;
  do _n_=1 to dim(vars);
    if missing(vars(_n_)) then do;
      deriver_var=catx(' ',deriver_var,vname(vars(_n_)));
    end;
  end;
run;

Art, CEO, AnalystFinder.com

 

Raffik
Calcite | Level 5

Thanks

novinosrin
Tourmaline | Level 20

@Raffik Please mark @art297 's solution as accepted and answered. Thank you!

lalohg
Quartz | Level 8

Dear Art,

how can I modify the code to get the deriver_var in a data set with several numeric and character variables like the attached example?

 

all your help will be appreciated

 

Thanks

Ed

 

 

 

art297
Opal | Level 21

I was unable to view your workbook, but here is one way to include both character and numeric variables:

data class;
  set sashelp.class;
  if _n_ in (2,8) then do;
    call missing(age);
    call missing(sex);
    call missing(weight);
  end;
run;

data want;
  set class;
  length deriver_var $50;
  array cvars(*) name sex;
  array nvars(*) age height weight;
  do _n_=1 to dim(cvars);
    if missing(cvars(_n_)) then do;
      deriver_var=catx(' ',deriver_var,vname(cvars(_n_)));
    end;
  end;
  do _n_=1 to dim(nvars);
    if missing(nvars(_n_)) then do;
      deriver_var=catx(' ',deriver_var,vname(nvars(_n_)));
    end;
  end;
run;

You could specify the numeric variables with _numeric_ rather than spelling them out. Unfortunately, you can't do the same with the character variables as deriver_var will be included in the list of character variables.

 

Art, CEO, AnalystFinder.com

 

lalohg
Quartz | Level 8
Hi Art,
Thanks for the code, unfortunately I have a data set with lots of numeric
and character variables, is there a way to include all of them in the code?


Here is what I intent to get:

I have:
id young home tree garden garage livingroom
1 2 8 yes 4 8
2 4 6 no
3 yes 8 8 4 1 7
4 yes 9 1 5
5 7 5 0 7 2 3
6 8 no 4 5 9
7 3 4 7 7 7
8 7 8 8
9 5 no 8 9
10 8 6 4 7 no 10
Would like to have:
Id deriver_var
1 garage
2 home garden livingroom
4 garden livingroom
6 home
7 young
8 young garden livingroom
9 tree garage


Thanks
Ed.


##- Please type your reply above this line. Simple formatting, no
attachments. -##
art297
Opal | Level 21

You could use _character_ and just exclude the new variable from the check. e.g.:

data class;
  set sashelp.class;
  if _n_ in (2,8) then do;
    call missing(age);
    call missing(sex);
    call missing(weight);
  end;
run;

data want;
  set class;
  length deriver_var $50;
  array cvars(*) _character_;
  array nvars(*) _numeric_;
  do _n_=1 to dim(cvars);
    if vname(cvars(_n_)) ne 'deriver_var' and missing(cvars(_n_)) then do;
      deriver_var=catx(' ',deriver_var,vname(cvars(_n_)));
    end;
  end;
  do _n_=1 to dim(nvars);
    if missing(nvars(_n_)) then do;
      deriver_var=catx(' ',deriver_var,vname(nvars(_n_)));
    end;
  end;
run;

Art, CEO, AnalystFinder.com

 

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!

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.

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
  • 7 replies
  • 1198 views
  • 3 likes
  • 4 in conversation