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

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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