Help using Base SAS procedures

DO LOOPS

Accepted Solution Solved
Reply
Super Contributor
Posts: 1,040
Accepted Solution

DO LOOPS


I am using a do loop in array and new variables being created  based on some if/then conditions;

If i did not reset the new variables to missing then there is a chance that their values are carried forward from previous if any of the future ones have a missing value???

is this only in the Do loops??

Thanks


Accepted Solutions
Solution
‎04-30-2013 06:27 PM
Super User
Posts: 10,487

Re: DO LOOPS

Any datastep with multiple Output statements will output the values of any variables at the time of execution. Do loops coupled with arrays are basically just a shorthand form of doing the same calculations multiple times.

For example;

varx = vary +3;

output;

varx = varz -2;

output;

creates two records with different values of varx but any other variables have the values at the time of the Output statement execution.

You only have to worry about the "carrying forward" of the missing values within the current execution of The Do loop. Fi a new value is NOT assigned for a variable then yes it will have the same value as the previous pass through the loop.

All the values are reset with values for the next record from Set or Input statements. (Warning: Retain statement is designed to work around this behavior. OR if you have multiple Set or Input statements things could get very confusing quickly.)

In one of your other posts I recommended a way to output a bunch of new variables corresponding to each variable in your arrays so that a corresponding outcome was directly tied to the input instead of a simple flag that basically said "one of the conditions was met somewhere in the comparisons". I believe that approach lends itself in general to better analysis in many cases because then it has which and how many of the comparisons were met/failed instead of trying to create very complicated logic straight.


View solution in original post


All Replies
Respected Advisor
Posts: 3,124

Re: DO LOOPS

Please give an example. Too much missing dots.

Haikuo

Solution
‎04-30-2013 06:27 PM
Super User
Posts: 10,487

Re: DO LOOPS

Any datastep with multiple Output statements will output the values of any variables at the time of execution. Do loops coupled with arrays are basically just a shorthand form of doing the same calculations multiple times.

For example;

varx = vary +3;

output;

varx = varz -2;

output;

creates two records with different values of varx but any other variables have the values at the time of the Output statement execution.

You only have to worry about the "carrying forward" of the missing values within the current execution of The Do loop. Fi a new value is NOT assigned for a variable then yes it will have the same value as the previous pass through the loop.

All the values are reset with values for the next record from Set or Input statements. (Warning: Retain statement is designed to work around this behavior. OR if you have multiple Set or Input statements things could get very confusing quickly.)

In one of your other posts I recommended a way to output a bunch of new variables corresponding to each variable in your arrays so that a corresponding outcome was directly tied to the input instead of a simple flag that basically said "one of the conditions was met somewhere in the comparisons". I believe that approach lends itself in general to better analysis in many cases because then it has which and how many of the comparisons were met/failed instead of trying to create very complicated logic straight.


☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

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