BookmarkSubscribeRSS Feed
Hello_there
Lapis Lazuli | Level 10

For example, let's say a study is still going and you're trying to count subjects who were in a control group, and you're making a table for reasons why they discontinued. Everyone is still in the study, so the data set can be updated later on. Let's say the variables were:

 

trt="control"

 

terminatedn= 2

 

Terminatedn is the numerical number represented by the reason why they were out of the study, and it ranges from 1-5. Doing a proc freq with an out statement won't work bc there are no observations bc everyone is still in the study. 

proc freq data=data;
table terminatedn*trt/ out=cnt;
where trt="Control" and terminatedn=2;
run;

What would be another way to code this so that it can be updated in the future when counts change from 0? 

 

The only way i can think of doing this is by brute force and using a proc sql multiple times like this:

proc sql;
 select count(distinct subjects) into: cnt_contrl2
 from data
 where trt="Control" and terminatedn=2;
quit;

This would produce a macro variable that's equal to 0, which i could put into a datalines data step. And then i can if the count is not equal to zero, then do: 

 

But maybe there's an easier way?

 

 

 

Thanks for taking it easy to me. I'm a new programmer. 

 

 

3 REPLIES 3
Astounding
PROC Star

Here's a step you could play with:

data _null_;
   if done then do;
      file print;
      put 'No subjects have terminated.';
   end;
   stop;
   set have end=done;
   where trt="Control" and terminatedn=2;
run;

Keep the PROC FREQ in the program.  Now what happens is only one step generates output.  If there are no terminated subjects, this step writes a message and PROC FREQ generates nothing.  If there are terminated subjects, PROC FREQ generates a table, while this new step generates nothing.

ballardw
Super User

Have you ever tried the MISSING option on a table:

 

proc freq data=data;table terminatedn*trt/missing out=cnt;where trt="Control";run;

Which will show terminatedn is missing but will count the values regardless.

Filter the OUT= data set for terminatedn=2 for other uses when you need  and expect that value to be present.

Hello_there
Lapis Lazuli | Level 10
Thanks for the reply, I have tried the missing option but i solved my issue by using PROC SUMMARY.
How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1056 views
  • 3 likes
  • 3 in conversation