BookmarkSubscribeRSS Feed
aaaaa34
Calcite | Level 5

Hi,

 

I have some problems with my macro.

 

I created all my variables using SAS code (code below). In "schools" variable I want to find only these cases which contain at least one value from "place" variable. Then I want to add to these cases the right values of "opinion" and "country" variables. The results should look like:

sas2.PNG

 

 

8 REPLIES 8
jarg
Fluorite | Level 6

you're not SETting anything in your last dataset - 

data &data_out;
set 
%let i_1 =1;

is this intended? i think you  just need to merge the two datasets together:

 

 

 

proc sort data=AAA; by SCHOOLS;
proc sort data=BBB; by place;

data &data_out;
merge BBB(rename=(place=SCHOOLS)) AAA; by place;

aaaaa34
Calcite | Level 5
Hi, It was intended. I don't know what's wrong with find function. And maybe this isn't good idea to put "opinion" and "country" variables in lists...
Tom
Super User Tom
Super User

No need for any code generation. Just write the code.

data aaa;
  input  schools: $50.;
datalines;
harvard
only_harvard
cheese_cake_pizza
wse_is_for_you
;
data bbb;
  input  place: $10. opinion: 2. country: $10.;
datalines;
Harvard 8 usa
oxford 8 uk
wse 9 france
;

proc sql ;
create table want as
  select a.schools,b.opinion,b.country
  from aaa a inner join bbb b
    on find(a.schools,b.place,'it')
  order by 1,2,3
;
quit;

proc print data=want;
run;
Obs    schools           opinion    country

 1     harvard              8       usa
 2     only_harvard         8       usa
 3     wse_is_for_you       9       france
aaaaa34
Calcite | Level 5
Thanks @Tom but I don't know what's wrong with my macro... and for my big datasets (here I write only part of them) I prefer macro
JackHamilton
Lapis Lazuli | Level 10

Before writing a macro that generates code, you should have an example of working code similar to what the macro should generate.

 

Your macro is generating 

 

    set find(schools,"&zm1") >0 

 

so SAS thinks that "find" is the name of a data set.  The parenthesis indicates that a data st option is to follow, but "schools" is not the name of a data set option.

 

What working code do you want to generate?

 

aaaaa34
Calcite | Level 5
Hi @JackHamilton, I'm new in SAS and I have to admit that I started my macro without any code... I don't know whether I think in proper way... maybe I shouldn't put "opinion" and "country" variables into lists but for example use join from SQL as Tom suggested
aaaaa34
Calcite | Level 5
@Tom what is "it" in find(a.schools,b.place,'it')?

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 8 replies
  • 1361 views
  • 0 likes
  • 4 in conversation