BookmarkSubscribeRSS Feed
shivam38
Calcite | Level 5

Hey I am working on a dataset in which I just want to print the total number of observation from a particular column how I can achieve this in proc report.

like I have mentioning a sample code here.

 

 

 

 

proc report data = shop;

column name type products price;

by type;

define products/group;

break after products/page;

run;

 

 

In this above example I just want to print the total number of products in each table, how can I do this help me /

Thank You in advance.

7 REPLIES 7
shivam38
Calcite | Level 5
I just want to do it in proc report method is it possible or not
Kurt_Bremser
Super User

See this example, gleaned from @Cynthia_sas's answer in https://communities.sas.com/t5/ODS-and-Base-Reporting/Proc-Report-how-to-get-distinct-count-of-a-var... :

data bankinfo;
infile datalines;
input acct amt;
return;
datalines;
123 100
123 150
123 300
456 200
456 200
890 100
890 100
890 100
890 50
991 100
991 250
;

proc report data=bankinfo nowd;
column acct;
define acct / group noprint;
rbreak after / summarize;
compute acct;
if _break_ = ' ' then cnt_uniq + 1;
endcomp;
compute after /
style={just=l};
line 'Number of Accounts:' cnt_uniq 2.0;
endcomp;
run;

Result:

Number of Accounts: 4

(Second hit of a Google search for "sas count distinct levels in proc report", see Maxim 6)

PaigeMiller
Diamond | Level 26

@shivam38 wrote:

Hey I am working on a dataset in which I just want to print the total number of observation from a particular column how I can achieve this in proc report.


Do you mean the number of DISTINCT levels of a variable?

--
Paige Miller
Ksharp
Super User
proc sort data=sashelp.class out=have;
by sex;
run;
proc report data=have nowd;
by sex;
column name age weight n;
define age/display;
define weight/display;
rbreak after/summarize;
run;
shivam38
Calcite | Level 5
it did not work sorry .
PaigeMiller
Diamond | Level 26

@shivam38 wrote:
it did not work sorry .

If that's all you tell us, we can't help further. You have not given us information that will help us figure out what the problem is.

 

When something doesn't work, SHOW US THE LOG for this PROC or DATA step! We want to see the entire LOG for this PROC or DATA step, that's 100%, all of it, without you selecting certain portions to show us.

--
Paige Miller

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 7 replies
  • 837 views
  • 0 likes
  • 4 in conversation