Hi,
I would like to find only these cases in which "schools" variable has at least one value from "place" variable. Then I want to also add to these cases the right values of "opinion" and "country" variables. Using datasets which I created in SAS (code below) the results should look like:
That's my code:
data aaa;
input schools: $50.;
datalines;
harvard
only_harvard
cheese_cake_pizza
wse_is_for_you
;
proc print data=aaa noobs;
run;
data bbb;
input place: $10. opinion: 2. country: $10.;
datalines;
harvard 8 usa
oxford 8 uk
wse 9 france
;
%macro xxx(data_out=);
%let listopinion=;
proc sql noprint;
select opinion
into :listopinion separated by "!"
from bbb
;
run;
quit;
%let listcountry=;
proc sql noprint;
select country
into :listcountry separated by "!"
from bbb
;
run;
quit;
%let listplace=;
proc sql noprint;
select place
into :listplace separated by "!"
from bbb
;
run;
quit;
data &data_out;
set
%let i_1 =1;
%let i_2 =1;
%let i_3 =1;
%do %until (%qscan(&listcountry,&i_3,'!') = %str());
%do %until (%qscan(&listopinion,&i_2,'!') = %str());
%do %until (%qscan(&listplace,&i_1,'!') = %str());
%let zm1=%scan(&listplace,&i_1,'!');
find(schools,"&zm1") >0
%let i_1=%eval(&i_1+1);
%end;
%let zm2=%scan(&listopinion,&i_2,'!');
%let i_2=%eval(&i_2+1);
%end;
%let zm3=%scan(&listcountry,&i_3,'!');
%let i_3=%eval(&i_3+1);
%end;
run;
keep school &zm1 &zm2 &zm3;
%mend;
%xxx(data_out=ddd);
Something like this?
proc sql;
select SCHOOLS, OPINION, COUNTRY
from AAA
,BBB
where index(SCHOOLS, PLACE, 't' );
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.
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.