Write and run SAS programs in your web browser

probelm using macro

Reply
Contributor
Posts: 31

probelm using macro

data cudata;
input ID Orderdate$ Model$12.  Quantity ;
cards;
287 15OCT03 DeltaBreeze 15
287 15OCT03 SantaAna    15
274 16OCT03 JetStream   1
174 17OCT03 SantaAna    20
174 17OCT03 Noreaster   5
174 17OCT03 Scirocco     1
347 18OCT03 Mistral      1
287 21OCT03 DeltaBreeze 30
287 21OCT03 SantaAna    25
run;


%macro cus(dsn);

%if &sysday=monday
%then  %do;
proc print data=&dsn;
run;
%end;

%else %if &sysday=friday
%then  %do;
proc summary data=&dsn;
class ID;
var Quantity ;

run;
%end;
%mend cus;

 

%cus(cudata)
 

No errors are coming up but still not getting the desire output

Grand Advisor
Posts: 9,740

Re: probelm using macro

The values of SYSDAY are Monday not monday, Friday not friday (capital first letter)

Either use the actual returned results for &SYSDAY or %upcase or %lowcase everything to match.

Contributor
Posts: 31

Re: probelm using macro

Hi, still the same result, any other thing that can be done?

##- Please type your reply above this line. Simple formatting, no
attachments. -##
Respected Advisor
Posts: 4,645

Re: probelm using macro

What result do you desire when the day is Thursday?

Contributor
Posts: 31

Re: probelm using macro

If it is run on monday then print a detaik report and if on friday then a
summary report (no other day)

##- Please type your reply above this line. Simple formatting, no
attachments. -##
Super User
Posts: 1,077

Re: probelm using macro

Add %put SYSDAY = &sysday; to your code;

Did you run it on Monday or Friday ?

 

If YES - please upload the results you got and what you expected to get/

Contributor
Posts: 31

Re: probelm using macro

Still the same no result.No i want to run it for thursday to give the
summary.i have changed the sysday frm friday to thursday now?

##- Please type your reply above this line. Simple formatting, no
attachments. -##
Respected Advisor
Posts: 4,645

Re: probelm using macro

Yes, if you want it to do something on a Thursday, you have to change friday to Thursday (not thursday).

Contributor
Posts: 31

Re: probelm using macro

Getting this error neither thr print option nor a valid output statement
has been given

##- Please type your reply above this line. Simple formatting, no
attachments. -##
Respected Advisor
Posts: 4,645

Re: probelm using macro

Yes, you put nonworking SAS code into a macro.  So it's no surprise that it still doesn't work.

 

Get your PROC SUMMARY to work outside of a macro.  Then you will know what to put into the macro.  It could be as simple as adding the word PRINT to the end of the PROC statement.  But you will need to inspect the results to see if it does what you want it to do.

Contributor
Posts: 31

Re: probelm using macro

my question is write a macro that prints a detail report if you run it on
monday and a summary report if you run it on friday(no other days)


now what should i do?






##- Please type your reply above this line. Simple formatting, no
attachments. -##
Grand Advisor
Posts: 16,335

Re: probelm using macro

@rishabhmehra13

1. Develop working non macro code

2. Figure out how to determine day of week. SYSDATE should not be used since it reflects the date when SAS started.

Use today() to get the date and then use WEEKDAY() to get the day of the week.

3. Place code in macro logic - test your logic first with %PUT statements to make sure the evaluate correctly.

 

Based on your initial code:

SYSDATE won't work - change using my comments in #2. Make sure to test what you're getting out of the today and weekday functions. 

 

Your macro logic is correct. Not sure why your proc summary may not work, I haven't read all the messages here. 

 

Respected Advisor
Posts: 4,645

Re: probelm using macro

This assignment is unfair.  

 

You need to understand that macro language doesn't generate any reports.  It only generates a SAS program.  When the SAS program runs, it can generate a report.  You can't make use of macro language until you know the SAS language statements it would take to generate the reports that you want.  With no macro language, you need to be able to construct a SAS language program that generates a detailed report, and a SAS language program that generates a summary report.  Only then can we talk about how to apply macro language.  (Just for the record, it looks like the macro portion of the program is in good shape.  But that's only part of the task.)  So develop those reporting programs with no macro language, make sure they work, get the format of the report approved so you won't need to change the SAS code later, and then they can be fit into the macro.

 

Contributor
Posts: 31

Re: probelm using macro

data cudata;
input ID Orderdate$ Model$12.  Quantity ;
cards;
287 15OCT03 DeltaBreeze 15
287 15OCT03 SantaAna    15
274 16OCT03 JetStream   1
174 17OCT03 SantaAna    20
174 17OCT03 Noreaster   5
174 17OCT03 Scirocco     1
347 18OCT03 Mistral      1
287 21OCT03 DeltaBreeze 30
287 21OCT03 SantaAna    25
run;


%macro cus(dsn);

%if &sysday=Monday
%then  %do;
proc print data=&dsn;
run;
%end;

%else %if &sysday=Thursday
%then  %do;
proc summary data=&dsn;
class ID;
var Quantity ;

run;

%end;
%put SYSDAY=&sysday;

%mend cus;

%cus(cudata);
 

Respected Advisor
Posts: 4,645

Re: probelm using macro

[ Edited ]

Looks right.  Did you test it?

 

I take it back.  PROC SUMMARY requires either the PRINT option or an OUTPUT statement.  Otherwise, there won't be any output.

Post a Question
Discussion Stats
  • 14 replies
  • 355 views
  • 2 likes
  • 5 in conversation