BookmarkSubscribeRSS Feed
ak2011
Fluorite | Level 6
Hi,
 I would greatly appreciate if somone could help me with the SAS code to count number of observations/records under each column variable in the attached table(Table 1).
My task is I want to count the number of pop cont and can cont under each of the variables lung loat lsquam ladeno.
I know that probably I need to use proc means or proc freq to do the counts but I am not sure about the right code.
 
Any help,please? Thanks in advance.
ak.
 
 
 
1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
72
73 /* Cell Types*/
74 data ncells(keep=lung loat lsquam ladeno);
75 set bgmg1(obs=70);
76 run;
 
NOTE: There were 70 observations read from the data set WORK.BGMG1.
NOTE: The data set WORK.NCELLS has 70 observations and 4 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.02 seconds
 
 
77
78 proc print data=ncells;
79 Title " Table 1. Cancer information";
80 run;
 
NOTE: There were 70 observations read from the data set WORK.NCELLS.
NOTE: PROCEDURE PRINT used (Total process time):
real time 0.43 seconds
cpu time 0.43 seconds
 
 
81
82 proc freq data=ncells;
83 run;
 
NOTE: There were 70 observations read from the data set WORK.NCELLS.
NOTE: PROCEDURE FREQ used (Total process time):
real time 0.24 seconds
cpu time 0.23 seconds
 
 
84
85 proc means data=ncells; run;
 
NOTE: There were 70 observations read from the data set WORK.NCELLS.
NOTE: PROCEDURE MEANS used (Total process time):
real time 0.17 seconds
cpu time 0.15 seconds
 
 
86
87
88 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
100

 

 

 

 

 

4 REPLIES 4
PaigeMiller
Diamond | Level 26

My task is I want to count the number of pop cont and can cont under each of the variables lung loat lsquam ladeno.

 

As I look at the output in your attached file, it seems as if you have programmed SAS to do this counting. So I'm not sure what you are asking.

--
Paige Miller
Reeza
Super User

This is overkill for what you want but definitely gives you that.

 

https://gist.github.com/statgeek/2de1faf1644dc8160fe721056202f111

 

Otherwise a PROC MEANS is likley all you need, assuming numeric variables - results are stored in the 'want' data set. The solution above works regardless of types.

 

proc means data=sashelp.class N NMISS;
ods output summary=want;
run;

proc print data=want;
run;

@ak2011 wrote:
Hi,
 I would greatly appreciate if somone could help me with the SAS code to count number of observations/records under each column variable in the attached table(Table 1).
My task is I want to count the number of pop cont and can cont under each of the variables lung loat lsquam ladeno.
I know that probably I need to use proc means or proc freq to do the counts but I am not sure about the right code.
 
Any help,please? Thanks in advance.
ak.
 
 
 
1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
72
73 /* Cell Types*/
74 data ncells(keep=lung loat lsquam ladeno);
75 set bgmg1(obs=70);
76 run;
 
NOTE: There were 70 observations read from the data set WORK.BGMG1.
NOTE: The data set WORK.NCELLS has 70 observations and 4 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.02 seconds
 
 
77
78 proc print data=ncells;
79 Title " Table 1. Cancer information";
80 run;
 
NOTE: There were 70 observations read from the data set WORK.NCELLS.
NOTE: PROCEDURE PRINT used (Total process time):
real time 0.43 seconds
cpu time 0.43 seconds
 
 
81
82 proc freq data=ncells;
83 run;
 
NOTE: There were 70 observations read from the data set WORK.NCELLS.
NOTE: PROCEDURE FREQ used (Total process time):
real time 0.24 seconds
cpu time 0.23 seconds
 
 
84
85 proc means data=ncells; run;
 
NOTE: There were 70 observations read from the data set WORK.NCELLS.
NOTE: PROCEDURE MEANS used (Total process time):
real time 0.17 seconds
cpu time 0.15 seconds
 
 
86
87
88 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
100

 

 

 

 

 


 

ballardw
Super User

You may get a better answer if you provide:

1) a small example data set as data step code.

2) What you expect for the result given that example data.

The example should be big enough to demonstrate some difference in the resulting count but small enough you can create the output by hand to show the desired result and layout.

 

Here's something similar to what I think you are wanting, a single table with the counts per column heading.

data example;
   input var1 $ var2 $ var3 $;
datalines;
A B  A
A A  B
A B  B
A B  A
B B  B
B A  A
B B  A
;

data temp;
   set example;
   array v var1 var2 var3;
   do i=1 to dim(v);
      name = vname(v[i]);
      value = v[i];
      output;
   end;
run;

proc tabulate data=temp;
   class name value;
   table value,name
   ;
run;
ak2011
Fluorite | Level 6
Thank you. I will provide a small dataset then.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 1684 views
  • 0 likes
  • 4 in conversation