DATA Step, Macro, Functions and more

How do I use DO LOOP to count number of responses that equal X

Reply
Occasional Contributor
Posts: 6

How do I use DO LOOP to count number of responses that equal X

[ Edited ]
 
PROC Star
Posts: 1,547

Re: How do I use DO LOOP to count number of responses that equal X

[ Edited ]

perhaps like this:

call missing(count);

do _n_=1 to dim(TwentyItems );

 if TwentyItems (_n_)='neutral' then count+1;

end;

 

 

or assign count=0 initial

 

count=0 ;

do _n_=1 to dim(TwentyItems );

 if TwentyItems (_n_)='neutral' then count+1;

end;

Occasional Contributor
Posts: 6

Re: How do I use DO LOOP to count number of responses that equal X

[ Edited ]
Posted in reply to novinosrin
 
PROC Star
Posts: 1,547

Re: How do I use DO LOOP to count number of responses that equal X

[ Edited ]

Are you sure, you are NOT dropping by accident at all?

 

CALL missing(KNeutral);

 

   IF TwentyItems {J} = 3 then KNeutral + 1;

 

The very moment the code complies, sas builds the descriptor portion of the dataset with all variables includingthe new assignment variable in the PDV(program data vector). There is not a chance this can be automatically dropped from your output. Please check thoroughly

Occasional Contributor
Posts: 6

Re: How do I use DO LOOP to count number of responses that equal X

[ Edited ]
Posted in reply to novinosrin
 
Super User
Posts: 23,224

Re: How do I use DO LOOP to count number of responses that equal X


FSHN wrote:

There variable is there, but I'm not getting my frequency tables to appear as I'd like. Thanks for help me get this far.


You haven't shown what you want or 'like', what you have or what your code is at this point so there's probably very little we can say regarding your problem at this point. 

 

A generic guess would be to transpose your data - don't bother trying to count it in a wide format - and then use PROC FREQ to summarize it.

 

Super User
Posts: 13,283

Re: How do I use DO LOOP to count number of responses that equal X


FSHN wrote:

There variable is there, but I'm not getting my frequency tables to appear as I'd like. Thanks for help me get this far.


And what does " I'm not getting my frequency tables to appear as I'd like." actually mean in coding terms? Do you have the frequency value but not in table of the desired format? The frequencies are incorrect? Something else?

 

Show what the desired table should look like and best would be to provide some example data to build a table with.

 

Perhaps you want one of the other procedures that will report a count such as Proc Report or Tabulate.

 

 

Super User
Posts: 23,224

Re: How do I use DO LOOP to count number of responses that equal X

And this is the reason, everyone with less than 100 pts gets their questions quoted....keep at it.

Ask a Question
Discussion stats
  • 7 replies
  • 243 views
  • 0 likes
  • 4 in conversation