Learning SAS? Welcome to the exclusive online community for all SAS learners.

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

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 12
Accepted Solution

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
Super User
Posts: 7,988

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;

 

View solution in original post


All Replies
Solution
‎08-05-2016 05:48 AM
Super User
Super User
Posts: 7,988

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: 7,854

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
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 342 views
  • 0 likes
  • 3 in conversation