BookmarkSubscribeRSS Feed
spg
Obsidian | Level 7 spg
Obsidian | Level 7
Hi,

I want to use the following code to create counts of groups. My only problem is that there are more than a 100 distinct types. Is there a smart way to do it?

proc sql;
create table a as
select distinct type1, type2, type3, count (*) as count
from b
group by type1, type2, type3;
quit;

Thanks.
8 REPLIES 8
DBailey
Lapis Lazuli | Level 10
That won't work if you're trying to get the number of combinations rather than the number of records in each combination. What does your data look like?
SPR
Quartz | Level 8 SPR
Quartz | Level 8
Hello SPG,

This is a solution:
[pre]
proc SQL;
select COUNT(distinct name) as nt into :nt
from SASHELP.vcolumn
where LIBNAME="WORK" and MEMNAME="B";
%let nt=%TRIM(&nt);
select name as name into :t1-:t&nt
from SASHELP.vcolumn
where LIBNAME="WORK" and MEMNAME="B";
quit;
%macro a;
%local i;
%do i=1 %to &nt;
proc SQL;
create table a&i as
select distinct &&t&i, COUNT(*) as count
from b
group by &&t&i
;quit;
%end;
%mend a;
%a
[/pre]
Sincerely,
SPR
spg
Obsidian | Level 7 spg
Obsidian | Level 7
Thanks much SPR! Though this is giving me some errors, I get the general idea and am working to use it for my purposes.
SPR
Quartz | Level 8 SPR
Quartz | Level 8
What errors did you get?

SPR
spg
Obsidian | Level 7 spg
Obsidian | Level 7
So sorry, I completely overlooked this.
Here is the error

WARNING: INTO Clause :t1 through :t0 does not specify a valid sequence of macro variables.
spg
Obsidian | Level 7 spg
Obsidian | Level 7
WARNING: INTO Clause :t1 through :t0 does not specify a valid sequence of macro variables.
NOTE: No rows were selected.
4093 quit;
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Check your PROC SQL output (turn on OPTIONS MACROGEN SYMBOLGEN; to start) -- no selected rows, so &nt resolves to "0" (zero).

Scott Barry
SBBWorks, Inc.
SPR
Quartz | Level 8 SPR
Quartz | Level 8
Hello SPG,

Pay attention on the following code:

where LIBNAME="WORK" and MEMNAME="B";

You have to use your library name instead of WORK, and its name should be in capital letters. The same is related to dataset name B.

Sincerely,
SPR

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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