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

Hello SAS community,

I'm wanting to know how to code an array that sets all numeric responses from all variables to missing.

The data set has more than 100 variables, so I would like to know a command/syntax that would allow me to have the array go through all the variables and change a numeric response to missing. I understand the array statement needs to change to do this and I've been able to find how to change the syntax for character using " _character_" , but not for all numeric values.

Below is sample code:

data new;

set old.library;

array numarray {3} length width height;

do i=1 to 3;

if numarray {i}= 999 then numarray {i}= .;

end;

drop i;

run;

1 ACCEPTED SOLUTION

Accepted Solutions
KachiM
Rhodochrosite | Level 12

Here is another example.

data want;

   set sashelp.class;

   array k

  • _numeric_;
  •    do i = 1 to dim(k);

          k = .;

       end;

    drop i;

    run;

    View solution in original post

    7 REPLIES 7
    stat_sas
    Ammonite | Level 13

    Hi,

    You can do it using _numeric_ for numeric variables. Make sure you have only variables in the data set which are required to be imputed as missing otherwise it will replace all the numeric variables in the data set with missing. Please see below the syntax:

    data new;

    set old.library;

    array numarray {*} _numeric_;

    do i=1 to dim(numarray);

    if numarray {i}= 999 then numarray {i}= .;

    end;

    drop i;

    run;

    Macyhe22
    Calcite | Level 5

    Thank you,

    Just to clarify what do you mean the variables all have to be imputed as missing, so that all the numerical values are changed to missing. I believe you mean that the values for all the variables have to have for example a designated number such as, 999, as a response like in the above syntax in order to be changed to missing?

    Is this the thinking? And I guess if a response doesn't then it would make all responses numeric. So, if not all variables have missing coded numerically in this way, I would have to code for missing "." in ranges of variables?

    My data set is a survey.

    Thank you!

    stat_sas
    Ammonite | Level 13

    This was just based on your coded example. In survey data this is a common practice to code don't know/refused responses as 999. Sometimes survey data also contains some demo questions like age, income, region etc., so if income variable has a value 999 that will also be imputed as missing as well and may impact the analysis.

    Macyhe22
    Calcite | Level 5

    I see! Thank you. I was looking at all the variables before putting in the code to change in the data set how missing is displayed and it is displayed as 996 or "missing".

    I find it tedious to see what variables exactly are which for missing or 996 specifically. 996 throughout the data set is representative for missing and not anything else, so it won't impact my analysis I assume.

    I ultimately want to create a missing data profile using the MI procedure, since my data set contains a lot of missing. The Missing data profile will then provide information to do multiple imputations for data analysis.

    I believe the MI procedure by default assumes "." as missing, so I'm trying to change 996 and missing in the variables to ".".

    Could I create a character and numeric array and have these two arrays account for all the data to convert all the data to "." for missing?

    Then I could do the MI procedure to see the missing data pattern?

    Thank you.

    stat_sas
    Ammonite | Level 13

    As you have already figured it out how to apply syntax for character using _character_ so just define two arrays in data step one for character and other for numeric to get the desired results.

    KachiM
    Rhodochrosite | Level 12

    Here is another example.

    data want;

       set sashelp.class;

       array k

  • _numeric_;
  •    do i = 1 to dim(k);

          k = .;

       end;

    drop i;

    run;

    Ksharp
    Super User

    You don't need array.

    call missing(of _numeric_);

    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
    • 7 replies
    • 2114 views
    • 5 likes
    • 4 in conversation