01-10-2016 12:16 PM
01-10-2016 12:58 PM - edited 01-10-2016 01:04 PM
The below is an example taken from google. how if _n_ works here. if i remind myself for PDV it should return only 1 entry as per condition _n_=1, how it returns all of below acctinfo values?
The data step have three main part
if _n_=1 then do; put @1 "proc format;" ; put @8 "value account"; end;
This part _surronded by DO and END_ will actually run one time, when reading the first observation from acctinfo dataset. Where the condition IF (_n_= 1) is true.
The second part of the code is the one that returns all of the acctinfo values, which run without any condition in each data step iteration.
put @8 acctnum @20 "= '" name "'";
Finally the part that run only when reading the last observation, where the condition IF (eof = true) is valid and that will happen only one time with you datset.
if eof then do; put @8 ";"; put @1 "run;"; end;
So the code within the first condition if _n_=1 is not the part that returns all the acctinfo values. But it will be valid for one time based on the condition and the two PUT statment will write to the file only one time.
01-13-2016 08:13 AM
Ideally it should return 1 if we think of PDV . however, it returns many values with this condition while use in the PROC format that i like to use for further use.
01-10-2016 01:47 PM
It's great to see that you searched and found a solution that you're trying to understsand.
I would like to mention that is not a good way to create a dynamic format.
You can use the CNTLIN to create a dataset without creating a new file and reading/executing it.
Example 8 in this paper demonstrates the method:
Here's a paper dedicated to that method alone: