DATA Step, Macro, Functions and more

Macro

Accepted Solution Solved
Reply
Contributor
Posts: 65
Accepted Solution

Macro

Here am creating a macro  here am creating two datasets x1 x2 from s1 s1 since i cud not access s1  s2 directly in proc sql

in macro,even in this way also  i cud  nt get the correct result,am getting error   ''File WORK.RUN.DATA does not exist''

.
              

%macro test_(test_,s1,s2);
data x1;
set &s1
run;

data x2;
set &s2;
run;

proc sql ;
create table &test_ as
select x1.classifications, x1.VSSTRESN as Active,
x2.VSSTRESN as placebo,sum(x1.VSSTRESN,x2.VSSTRESN ) as total
from x1,x2 where x1.classifications=x2.classifications;
quit;

%mend;

even i cud nt access  the data in the following way also

proc sql ;
create table &test_ as
select &s1.classifications, &s1.VSSTRESN as Active,
&s2.VSSTRESN as placebo,sum(&s1.VSSTRESN,&s2.VSSTRESN ) as total
from &s1,&s2 where &s1.classifications=&s1.classifications;
quit;

 

 

%test_(test100,r1,r2);

 

 

cup u pls help me out.


Accepted Solutions
Solution
‎03-28-2017 12:42 PM
Super User
Posts: 5,498

Re: Macro

You have situations where you are referring to a macro variable, and attempting to append text after it.  For example:

 

&s1.classifications

 

That's incorrect.  The dot actually delimits the name of the macro variable, so where you hope to generate:

 

r1.classifications

 

You are actually generating:

 

r1classifications

 

In order to get r1.classifications, you need two dots:  one to delimit the name of the macro variable, and a second dot becomes text following the macro variable value:

 

&s1..classifications

View solution in original post


All Replies
Super User
Posts: 7,762

Re: Macro

Writing in plain English might make it easier for non-native speakers to follow you.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Trusted Advisor
Posts: 1,913

Re: Macro

[ Edited ]

Can you attach the SASLOG so we can see not just this macro but the steps before? This error sometimes is caused by a missing semicolon somewhere, but SAS is looking for a dataset named RUN and it doesn't find it.

 

Agreeing with @KurtBremser, writing in proper English would also help.

Super User
Posts: 19,771

Re: Macro

Posted in reply to PaigeMiller

And from @PaigeMiller comment your first data step is missing a semicolon. 

 

 

Trusted Advisor
Posts: 1,913

Re: Macro


Reeza wrote:

And from @PaigeMiller comment your first data step is missing a semicolon. 

 

 


Even though I knew that was the problem, I failed to see the missing semicolon!

Solution
‎03-28-2017 12:42 PM
Super User
Posts: 5,498

Re: Macro

You have situations where you are referring to a macro variable, and attempting to append text after it.  For example:

 

&s1.classifications

 

That's incorrect.  The dot actually delimits the name of the macro variable, so where you hope to generate:

 

r1.classifications

 

You are actually generating:

 

r1classifications

 

In order to get r1.classifications, you need two dots:  one to delimit the name of the macro variable, and a second dot becomes text following the macro variable value:

 

&s1..classifications

Contributor
Posts: 20

Re: Macro

Try this: 

 

%macro test_(test_,s1,s2);
data x1;
set &s1; /*semi-colon was missing*/
run;

data x2;
set &s2;
run;

proc sql ;
create table &test_ as
select x1.classifications,
x1.VSSTRESN as Active,
x2.VSSTRESN as placebo,
sum(x1.VSSTRESN,x2.VSSTRESN ) as total
from x1,x2
where x1.classifications=x2.classifications;
quit;

%mend;

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 180 views
  • 1 like
  • 6 in conversation