BookmarkSubscribeRSS Feed
rishabhmehra13
Calcite | Level 5

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

14 REPLIES 14
ballardw
Super User

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.

rishabhmehra13
Calcite | Level 5
Hi, still the same result, any other thing that can be done?

##- Please type your reply above this line. Simple formatting, no
attachments. -##
Astounding
PROC Star

What result do you desire when the day is Thursday?

rishabhmehra13
Calcite | Level 5
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. -##
Shmuel
Garnet | Level 18

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/

rishabhmehra13
Calcite | Level 5
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. -##
Astounding
PROC Star

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

rishabhmehra13
Calcite | Level 5
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. -##
Astounding
PROC Star

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.

rishabhmehra13
Calcite | Level 5
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. -##
Reeza
Super User

@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. 

 

Astounding
PROC Star

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.

 

rishabhmehra13
Calcite | Level 5

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);
 

Astounding
PROC Star

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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 14 replies
  • 1780 views
  • 2 likes
  • 5 in conversation