turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- Base SAS Programming
- /
- How to Return Each Value in Temporary Array

Topic Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

08-30-2017 02:23 PM

The code I have below takes the current and previous 7 observations of INV_CR_t and returns the higest, lowest, and Sum of the values. For troubleshooting purposes I'd like to be able to see each value from the array on every observation, not just the min and max values. Is there anything I can do to update this code

```
data Want;
array p{0:7} _temporary_;
set have;
by STATE PlAN LAG;
p{mod(_n_,8)} = var_8;
min= min(of p{*});
max= max(of p{*});
Sum = sum(of p{*});
run;
```

To go from data that looks like this

State | Plan | Lag | Var1 |

OR | a | 0 | 32 |

OR | a | 0 | 43 |

OR | a | 0 | 46 |

OR | a | 0 | 69 |

OR | a | 0 | 12 |

OR | a | 0 | 25 |

OR | a | 0 | 39 |

OR | a | 0 | 64 |

OR | a | 0 | 65 |

OR | a | 0 | 8 |

OR | a | 0 | 67 |

OR | a | 0 | 12 |

OR | a | 0 | 58 |

OR | a | 0 | 5 |

OR | a | 0 | 23 |

OR | a | 0 | 39 |

OR | a | 0 | 50 |

OR | a | 0 | 57 |

OR | a | 0 | 27 |

OR | a | 0 | 41 |

OR | a | 0 | 16 |

OR | a | 0 | 27 |

OR | a | 0 | 49 |

OR | a | 0 | 34 |

OR | a | 0 | 41 |

To data that looks like this (it doesn't matter to me whether the variables descend from first to last observation or otherwise):

State | Plan | Lag | Var1 | Var2 | Var3 | Var4 | Var5 | Var6 | Var7 | Var8 | Min | Max | Sum |

OR | a | 0 | 32 | ||||||||||

OR | a | 0 | 43 | ||||||||||

OR | a | 0 | 46 | ||||||||||

OR | a | 0 | 69 | ||||||||||

OR | a | 0 | 12 | ||||||||||

OR | a | 0 | 25 | ||||||||||

OR | a | 0 | 39 | ||||||||||

OR | a | 0 | 64 | 39 | 25 | 12 | 69 | 46 | 43 | 32 | 12 | 69 | 266 |

OR | a | 0 | 65 | 64 | 39 | 25 | 12 | 69 | 46 | 43 | 12 | 69 | 298 |

OR | a | 0 | 8 | 65 | 64 | 39 | 25 | 12 | 69 | 46 | 8 | 69 | 320 |

OR | a | 0 | 67 | 8 | 65 | 64 | 39 | 25 | 12 | 69 | 8 | 69 | 282 |

OR | a | 0 | 12 | 67 | 8 | 65 | 64 | 39 | 25 | 12 | 8 | 67 | 280 |

OR | a | 0 | 58 | 12 | 67 | 8 | 65 | 64 | 39 | 25 | 8 | 67 | 280 |

OR | a | 0 | 5 | 58 | 12 | 67 | 8 | 65 | 64 | 39 | 5 | 67 | 313 |

OR | a | 0 | 23 | 5 | 58 | 12 | 67 | 8 | 65 | 64 | 5 | 67 | 279 |

OR | a | 0 | 39 | 23 | 5 | 58 | 12 | 67 | 8 | 65 | 5 | 67 | 238 |

OR | a | 0 | 50 | 39 | 23 | 5 | 58 | 12 | 67 | 8 | 5 | 67 | 212 |

OR | a | 0 | 57 | 50 | 39 | 23 | 5 | 58 | 12 | 67 | 5 | 67 | 254 |

OR | a | 0 | 27 | 57 | 50 | 39 | 23 | 5 | 58 | 12 | 5 | 58 | 244 |

OR | a | 0 | 41 | 27 | 57 | 50 | 39 | 23 | 5 | 58 | 5 | 58 | 259 |

OR | a | 0 | 16 | 41 | 27 | 57 | 50 | 39 | 23 | 5 | 5 | 57 | 242 |

OR | a | 0 | 27 | 16 | 41 | 27 | 57 | 50 | 39 | 23 | 16 | 57 | 253 |

OR | a | 0 | 49 | 27 | 16 | 41 | 27 | 57 | 50 | 39 | 16 | 57 | 257 |

OR | a | 0 | 34 | 49 | 27 | 16 | 41 | 27 | 57 | 50 | 16 | 57 | 267 |

OR | a | 0 | 41 | 34 | 49 | 27 | 16 | 41 | 27 | 57 | 16 | 57 | 251 |

Accepted Solutions

Solution

08-30-2017
02:51 PM

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to acemanhattan

08-30-2017 02:29 PM - edited 08-30-2017 02:32 PM

Do you mean you wanna keep the array elements?

```
data Want;
```**array p{0:7} p0-p7 ;**

retain p;
set have;
by STATE PlAN LAG;
p{mod(_n_,8)} = var_8;
min= min(of p{*});
max= max(of p{*});
Sum = sum(of p{*});
run;

See if this helps,

HTH

All Replies

Solution

08-30-2017
02:51 PM

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to acemanhattan

08-30-2017 02:29 PM - edited 08-30-2017 02:32 PM

Do you mean you wanna keep the array elements?

```
data Want;
```**array p{0:7} p0-p7 ;**

retain p;
set have;
by STATE PlAN LAG;
p{mod(_n_,8)} = var_8;
min= min(of p{*});
max= max(of p{*});
Sum = sum(of p{*});
run;

See if this helps,

HTH

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to novinosrin

08-30-2017 02:50 PM

This is exactly what I needed! Thanks.

Is there a simple way to get the variables listed at the far right of my data, instead of on the left

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to acemanhattan

08-30-2017 03:01 PM - edited 08-30-2017 03:01 PM

Well, of course yes. Basically, you simply need to allow the compiler to compile your input dataset variables before compiling array elements as it constructs the PDV. And so how do you do that-

* Swap *

data Want;**set have;****by STATE PlAN LAG;****array p{0:7} p0-p7 ; retain p;**

p{mod(_n_,8)} = var_8;

min= min(of p{*});

max= max(of p{*});

Sum = sum(of p{*});

run;

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to novinosrin

08-30-2017 03:38 PM

Ah, too easy! Thanks.