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' );
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
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.
Ready to level-up your skills? Choose your own adventure.