DATA Step, Macro, Functions and more

Error while running the given program

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 7
Accepted Solution

Error while running the given program

[ Edited ]


%macro ordata(month,year);
proc print data="/folders/myfolders/macro/order_fact.sas7bdat";

where month(Order_date) =&month and year(Order_date)=&year;
if order_type=1 then count+1;
run;
%mend;
%ordata(2,2007)


Accepted Solutions
Solution
‎08-04-2016 04:46 PM
Super User
Posts: 5,081

Re: Error while running the given program

I'd suggest you try to debug this by getting rid of the macro language.  Just run a PROC PRINT with hard-coded values of 2 for &MONTH and 2007 for &YEAR, and see what it takes to fix up the program.

View solution in original post


All Replies
Solution
‎08-04-2016 04:46 PM
Super User
Posts: 5,081

Re: Error while running the given program

I'd suggest you try to debug this by getting rid of the macro language.  Just run a PROC PRINT with hard-coded values of 2 for &MONTH and 2007 for &YEAR, and see what it takes to fix up the program.

Occasional Contributor
Posts: 7

Re: Error while running the given program

%macro ordata(month,year);
proc print data="/folders/myfolders/macro/order_fact.sas7bdat";
where month(Order_date) =&month and year(Order_date)=&year;
run;
%mend;
%ordata(2,2007)
working perfect
Occasional Contributor
Posts: 7

Re: Error while running the given program


%macro order_internet(month, year);
proc print data = "/folders/myfolders/macro/order_fact.sas7bdat"; ;
set work.order_fact end = eof;/* named eof.. value of eof will be 1 for last iteration */
where month(Order_date) = &month and year(Order_date) = &year;
if order_type = 3 then count + 1;
if eof = 1 and count > 0 then do;
call symputx('title','Some Internet Orders'); call symputx('count',count); end;
else if eof = 1 and count = 0 then do; call symputx('title','No internet Orders'); call symputx('count',0); end;
run;
title "&title";
title2 "Total Internet Orders are &count";
proc print data = orders;
run;
%mend;
%order_internet(2,2007);

I wan to run this program could you please tell me how can I assign value to set function
Super User
Posts: 5,081

Re: Error while running the given program

Here are some basics that you will need to learn.

 

The SET statement names the incoming SAS data set.  All you have to do is give the name of the data set.

 

The first PROC PRINT should not be a PROC PRINT at all.  The statements that follow it are not allowed within a PROC PRINT.  Instead, it should probably be:

 

data orders;

 

The DATA statement names the SAS data set  you would like to create, so that the second PROC PRINT can name it as the data set to be printed.

 

Once again, I would suggest you get rid of the macro language.  Get the program to work first, without a macro.  Once it works, worry about converting the program to a macro. 

Occasional Contributor
Posts: 7

Re: Error while running the given program

[ Edited ]

Thank you. I got your idea and i changed the format now it is working...


%macro order_internet(month, year);
data new;
set wombat.order_fact end=enof;
where month(Order_date) =&month and year(Order_date)=&year;
if order_type =3 then count +1;
if eof =1 and count>0 then do;
call symputx('title','Some Internet Orders'); call symputx('count',count); end;
else if eof = 1 and count = 0 then do; call symputx('title','No internet Orders'); call symputx('count',0); end;
run;
title "&title";
title2 "Total Internet Orders are &count";
proc print data = new;
run;
%mend;
%order_internet(2,2007)
%order_internet(4,2007)

☑ This topic is SOLVED.

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

Discussion stats
  • 5 replies
  • 221 views
  • 0 likes
  • 2 in conversation