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.
proc sql;
select count(distinct products)
from shop;
quit;
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)
@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?
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 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.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.