DATA Step, Macro, Functions and more

Solution needed with both datastep and report procedure

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 19
Accepted Solution

Solution needed with both datastep and report procedure

Input:

21

22

21

21

23

22

21

21

22

23

22

Needed ouput:

distinct   times

21           5

22           4

23           2


Accepted Solutions
Solution
‎01-22-2017 04:19 PM
Super User
Posts: 5,498

Re: Solution needed with both datastep and report procedure

Getting the total should be just for reporting purposes and not part of the data itself.  One way:

 

proc freq data=have;

tables distinct / noprint out=counts (keep=distinct count rename=(count=times));

run;

 

proc print data=counts;

var distinct times;

sum times;

run;

View solution in original post


All Replies
Occasional Contributor
Posts: 19

Re: Solution needed with both datastep and report procedure

Sorry, I need the total for time too.
Needed ouput:

distinct times

21 5

22 4

23 2
Total 11
Trusted Advisor
Posts: 1,554

Re: Solution needed with both datastep and report procedure

data test;

     input var;

datalines;

21

22

21

21

23

22

21

21

22

23

22

;run;

 

1) proc freq data=test; table var; run;      

 

2) proc means data=test;

    class;

    var var;

    output out=test1 N=;

    run;

 

   I haven't run it so check it carefully.

Solution
‎01-22-2017 04:19 PM
Super User
Posts: 5,498

Re: Solution needed with both datastep and report procedure

Getting the total should be just for reporting purposes and not part of the data itself.  One way:

 

proc freq data=have;

tables distinct / noprint out=counts (keep=distinct count rename=(count=times));

run;

 

proc print data=counts;

var distinct times;

sum times;

run;

☑ This topic is solved.

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

Discussion stats
  • 3 replies
  • 143 views
  • 1 like
  • 3 in conversation