BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.

Hello,

How can I get the equivalent of this solution in sql?

 

data test;
input
commune $	etablissement $	effectif_etablissement $	identifiant	it1	it2	it3	it4;
cards;
971BA	Mau	  20	1	9	2	2	2
971BA	Mau	  20	2	0	1	9	9
971BA	Cham  22	12	1	9	2	0
971BA	Cham  22	14	2	1	9	0
971STC	Issa  23	27	1	1	9	9
971STC	Issa  23	31	9	0	9	9
971VFO	Ving  23	54	1	9	0	0
971VFO	Ving  23	58	1	2	1	1
971GOU	Dora  20	72	1	1	1	9
971GOU	Dora  20	77	1	1	9	0
;
run;

proc freq data=test(keep=etablissement it1) noprint ;
tables etablissement*it1 / out=freq_it1 (drop=percent) sparse;		 
run ;

thank You

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21
proc sql;
create table freq_it1 as
select a.etablissement, b.it1, count(c.it1) as COUNT
from
    (select distinct etablissement from test) as a cross join
    (select distinct it1 from test) as b left join
    test as c on a.etablissement=c.etablissement and b.it1=c.it1
group by a.etablissement, b.it1;
quit;
PG

View solution in original post

2 REPLIES 2
novinosrin
Tourmaline | Level 20
data test;
input
commune $	etablissement $	effectif_etablissement $	identifiant	it1	it2	it3	it4;
cards;
971BA	Mau	  20	1	9	2	2	2
971BA	Mau	  20	2	0	1	9	9
971BA	Cham  22	12	1	9	2	0
971BA	Cham  22	14	2	1	9	0
971STC	Issa  23	27	1	1	9	9
971STC	Issa  23	31	9	0	9	9
971VFO	Ving  23	54	1	9	0	0
971VFO	Ving  23	58	1	2	1	1
971GOU	Dora  20	72	1	1	1	9
971GOU	Dora  20	77	1	1	9	0
;
run;
proc sql;
create table x as
select etablissement,it1
from ((select distinct  etablissement from test ),(select distinct it1   from test ));
quit;


proc sql;
create table want as
select a.etablissement,a.it1,count(b.it1) as freq
from x a left join test b
on a.etablissement=b.etablissement and a.it1=b.it1
group by a.etablissement,a.it1;
quit;

But why the tedious process, although the task makes me learn regardless

PGStats
Opal | Level 21
proc sql;
create table freq_it1 as
select a.etablissement, b.it1, count(c.it1) as COUNT
from
    (select distinct etablissement from test) as a cross join
    (select distinct it1 from test) as b left join
    test as c on a.etablissement=c.etablissement and b.it1=c.it1
group by a.etablissement, b.it1;
quit;
PG

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!

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
  • 2 replies
  • 940 views
  • 3 likes
  • 3 in conversation