- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Posted 09-09-2020 07:25 AM
(710 views)
data dsn2;
set sashelp.class;
n=1;
do while (n<5);
n+1;
end;output;
run;i want below output using do while and do until loops
Name Sex Age Height Weight
| Alfred | M | 14 | 69.0 | 112.5 |
| Alice | F | 13 | 56.5 | 84.0 |
| Barbara | F | 13 | 65.3 | 98.0 |
| Carol | F | 14 | 62.8 | 102.5 |
| Henry | M | 14 | 63.5 | 102.5 |
2 REPLIES 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
The code you posted is just going to create a new variable named N with the same value on every observation, so the output will look nothing like what you say you want.
Can you describe in words what you want as the output?
Looks like you just want to use one of these data steps instead, none of which need DO WHILE or DO UNTIL.
data want;
set sashelp.class;
if _n_<= 5;
run;
data want;
set sashelp.class;
if _n_>5 then stop;
run;
data want;
set sashelp.class (obs=5);
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Generally, DO WHILE is not for selecting rows, or iterating over rows.
data dsn2;
set sashelp.class(obs=5);
run;
or
data dsn2;
set sashelp.class;
if _n_<=5;
run;
--
Paige Miller
Paige Miller