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

Hi all. I was passed along a program that contains the following data step. It recodes ALL missing numeric values to 0. 

 

But I don't understand how it's doing it?  In particular I don't understand the keywords 'change', '_numeric_', and 'do over'.  Can anyone help me understand how this code works?  Any pointers would be most appreciated.

 

/* RECODE ALL NUMBERIC MISSING VALUES FROM . TO 0 */
DATA WANT;
   SET HAVE;
   ARRAY CHANGE _NUMERIC_;
        DO OVER CHANGE;
            IF CHANGE=. THEN CHANGE=0;
        END;
RUN;

 

Also, do you feel this is a good way of doing this task or are there better alternatives? 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

HI @buechler66  

 

1. First off, do over array is an implicit array. Most people would suggest not to use implicit array as it's been deprecated.

2. The implicit array creates an automatic index variable _i_ in the PDV , however the index variable is not written to the output dataset.

3. _numeric_ is a keyword for grouping all numeric variable as elements in your array "change". So once your array is declared at compile time, sas groups the num vars with a non scalar value for the array identifier. 

4. What actually happens is

Your

DO OVER CHANGE;
IF CHANGE=. THEN CHANGE=0;
END;

resolves to

 

do _i_=1 to dim(change); /*dim(change) is total number of num elements(vars) that's been grouped*/ 

if change(_i_)=. then change(_i_)=0;

end;

 

I hope this helps.

 

Best regards!

 

 

 

 


@buechler66 wrote:

Hi all. I was passed along a program that contains the following data step. It recodes ALL missing numeric values to 0. 

 

But I don't understand how it's doing it?  In particular I don't understand the keywords 'change', '_numeric_', and 'do over'.  Can anyone help me understand how this code works?  Any pointers would be most appreciated.

 

/* RECODE ALL NUMBERIC MISSING VALUES FROM . TO 0 */
DATA WANT;
   SET HAVE;
   ARRAY CHANGE _NUMERIC_;
        DO OVER CHANGE;
            IF CHANGE=. THEN CHANGE=0;
        END;
RUN;

 

Also, do you feel this is a good way of doing this task or are there better alternatives? 


 

View solution in original post

4 REPLIES 4
VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

That way of doing it works.

here is a link to the same code you have provided that has the solution.

 

https://communities.sas.com/t5/SAS-Procedures/How-to-set-all-missing-values-to-zero-for-all-variable...

 

novinosrin
Tourmaline | Level 20

HI @buechler66  

 

1. First off, do over array is an implicit array. Most people would suggest not to use implicit array as it's been deprecated.

2. The implicit array creates an automatic index variable _i_ in the PDV , however the index variable is not written to the output dataset.

3. _numeric_ is a keyword for grouping all numeric variable as elements in your array "change". So once your array is declared at compile time, sas groups the num vars with a non scalar value for the array identifier. 

4. What actually happens is

Your

DO OVER CHANGE;
IF CHANGE=. THEN CHANGE=0;
END;

resolves to

 

do _i_=1 to dim(change); /*dim(change) is total number of num elements(vars) that's been grouped*/ 

if change(_i_)=. then change(_i_)=0;

end;

 

I hope this helps.

 

Best regards!

 

 

 

 


@buechler66 wrote:

Hi all. I was passed along a program that contains the following data step. It recodes ALL missing numeric values to 0. 

 

But I don't understand how it's doing it?  In particular I don't understand the keywords 'change', '_numeric_', and 'do over'.  Can anyone help me understand how this code works?  Any pointers would be most appreciated.

 

/* RECODE ALL NUMBERIC MISSING VALUES FROM . TO 0 */
DATA WANT;
   SET HAVE;
   ARRAY CHANGE _NUMERIC_;
        DO OVER CHANGE;
            IF CHANGE=. THEN CHANGE=0;
        END;
RUN;

 

Also, do you feel this is a good way of doing this task or are there better alternatives? 


 

buechler66
Barite | Level 11
Wow. That's a very helpful explanation. That's so much for taking the time.
novinosrin
Tourmaline | Level 20

You are welcome. Have a nice day!

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!

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