BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
singhsahab
Lapis Lazuli | Level 10

Dear Members,

 

I've a dataset which contain missing and non missing values. The "Spec" dataset contains the information about first dataset. I wanted to check missing values variable and wanted to create one more dataset which should contain the original dataset with one extra variable . I got stuck how i can concatenate variable names.  

Output wanted:

a b c Missing_Details

1 . a1 B is missing
. 2 b2 A is missing
. . A is missing,B is missing,C is missing
1 2 c3

 

data test;
infile datalines;
input a b c $1.;
datalines;
1 . a
. 2 b
. .  
1 2 c
;
run;

data Spec;
input Req  name $ TYPE $;
datalines;
0 a NUM
0 b NUM
0 C CHAR
;
run;

proc sql;
select name into :name1 SEPARATED by ' ' from spec WHERE TYPE EQ 'NUM';
select name into :name_CH1 SEPARATED by ' ' from spec WHERE TYPE EQ 'CHAR';
quit;

OPTIONS MPRINT MLOGIC SYMBOLGEN;

DATA _NULL;
SET TEST;
ARRAY ARR[*] &name1;
array arr1[*] &name_ch1;
DO J=1 TO dim(ARR);
  IF MISSING(ARR[J]) THEN MISS='MISSING';
 END; 
 DO i=1 TO dim(arr1);
  IF MISSING(ARR1[i]) THEN MISS='MISSING';
END;
RUN;

Thank you everyone in advance !! 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

Using what you've posted here a solution approach. 

DATA want(drop=i j);
  SET TEST;
  ARRAY ARR[*] &name1;
  array arr1[*] &name_ch1;
  length Missing_Details $120;

  DO J=1 TO dim(ARR);
    IF MISSING(ARR[J]) THEN
      Missing_Details=catx(',',Missing_Details,vname(ARR[J]));
  END;

  DO i=1 TO dim(arr1);
    IF MISSING(ARR1[i]) THEN
      Missing_Details=catx(',',Missing_Details,vname(ARR1[i]));
  END;
RUN;
proc print data=want;
run;

N.B: The length of variable Missing_Details must be sufficient to hold all the variable names in case they are all missing (=32 characters for the var name plus 1 character for the comma per variable).

View solution in original post

2 REPLIES 2
gamotte
Rhodochrosite | Level 12

Hello,

 

data test;
    infile datalines;
    input a b c $1.;

    array n _NUMERIC_;
    array ch _CHARACTER_;

    length miss $200;

    do over n;
        if missing(n) then miss=catx(' ', miss, vname(n), 'is missing');
    end;

    do over ch;
        if missing(ch) then miss=catx(' ', miss, vname(ch), 'is missing');
    end;

    datalines;
1 . a
. 2 b
. . . 
1 2 c
;
run;

Patrick
Opal | Level 21

Using what you've posted here a solution approach. 

DATA want(drop=i j);
  SET TEST;
  ARRAY ARR[*] &name1;
  array arr1[*] &name_ch1;
  length Missing_Details $120;

  DO J=1 TO dim(ARR);
    IF MISSING(ARR[J]) THEN
      Missing_Details=catx(',',Missing_Details,vname(ARR[J]));
  END;

  DO i=1 TO dim(arr1);
    IF MISSING(ARR1[i]) THEN
      Missing_Details=catx(',',Missing_Details,vname(ARR1[i]));
  END;
RUN;
proc print data=want;
run;

N.B: The length of variable Missing_Details must be sufficient to hold all the variable names in case they are all missing (=32 characters for the var name plus 1 character for the comma per variable).

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 917 views
  • 0 likes
  • 3 in conversation