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 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

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

View all other training opportunities.

Discussion stats
  • 2 replies
  • 700 views
  • 3 likes
  • 3 in conversation