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


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

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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

2 REPLIES 2
Haikuo
Onyx | Level 15

Please give an example. Too much missing dots.

Haikuo

ballardw
Super User

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.


sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

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