## how to limit the number of row when using put _all_??

Solved
Occasional Contributor
Posts: 12

# how to limit the number of row when using put _all_??

Is there anyway to control the number rows of its variables when using 'put _all_'?

For example)

I would like it to return the first 3 rows of variables instead of all.

data _null;

input x y;

put _all;

datalines;

1 3

3 4

34 55

2  3

2 33

4 5

;

run;

Thank you all!

Accepted Solutions
Solution
‎08-05-2016 05:48 AM
Super User
Posts: 9,599

## Re: how to limit the number of row when using put _all_??

[ Edited ]

There is an automatic variable _n_ which is observation number, use conditional on that (note also your typo: _all_) (note also your typo: _null_):

```data _null_;
input x y;
if _n_ <= 3 then put _all_;
datalines;
1 3
3 4
34 55
2  3
2 33
4 5
;
run;```

All Replies
Solution
‎08-05-2016 05:48 AM
Super User
Posts: 9,599

## Re: how to limit the number of row when using put _all_??

[ Edited ]

There is an automatic variable _n_ which is observation number, use conditional on that (note also your typo: _all_) (note also your typo: _null_):

```data _null_;
input x y;
if _n_ <= 3 then put _all_;
datalines;
1 3
3 4
34 55
2  3
2 33
4 5
;
run;```

Super User
Posts: 10,280

## Re: how to limit the number of row when using put _all_??

You will need an additional infile statement to restrict the number of lines(rows):

``````data _null_;
infile cards obs=3;
input x y;
put _all_;
datalines;
1 3
3 4
34 55
2  3
2 33
4 5
;
run;``````
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
☑ This topic is solved.