BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Tal
Pyrite | Level 9 Tal
Pyrite | Level 9

hi all,

The dataset orders gets created ,nothing's wrong my infile but my micro code not working.Anyone knows why,please?

PS.at least for sysday=wed should work but it doesnot. And in additon to this can i use the second code below for the same purpose.Will it work.Can i use automatic macro variables within a sas code?

options mprint;

DATA orders;

INFILE 'C:\Users\Trajce\Contacts\Desktop\Orders.txt';

INPUT CustomerID $ 1-3 OrderDate DATE7. Model $ 13-24 Quantity;

RUN;

%MACRO reports;

%IF &SYSDAY = Monday %THEN %DO;

PROC PRINT DATA = orders NOOBS;

FORMAT OrderDate DATE7.;

TITLE "&SYSDAY Report: Current Orders";

%END;

%ELSE %IF &SYSDAY = WEDNESDAY %THEN %DO;

PROC TABULATE DATA = orders;

CLASS CustomerID;

VAR Quantity;

TABLE CustomerID ALL, Quantity;

TITLE "&SYSDAY Report: Summary of Orders";

%END;

%MEND reports;

RUN;

%reports

RUN;

second code:

DATA orders;

INFILE 'C:\Users\Trajce\Contacts\Desktop\Orders.txt';

INPUT CustomerID $ 1-3 OrderDate DATE7. Model $ 13-24 Quantity;

IF &SYSDAY = Monday THEN DO;

PROC PRINT DATA = orders NOOBS;

FORMAT OrderDate DATE7.;

TITLE "&SYSDAY Report: Current Orders";

END;

ELSE IF &SYSDAY = WEDNESDAY THEN DO;

PROC TABULATE DATA = orders;

CLASS CustomerID;

VAR Quantity;

TABLE CustomerID ALL, Quantity;

TITLE "&SYSDAY Report: Summary of Orders";

END;

RUN;

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Are you running in EG or Base?

What does the log say when you run that line of code.

%put &sysday;

View solution in original post

13 REPLIES 13
Reeza
Super User

SAS is case sensitive.

It should be Wednesday not WEDNESDAY.

Tal
Pyrite | Level 9 Tal
Pyrite | Level 9

it was actually Wednesday  and then changed to WEDNESDAY.Did not work in either way

Reeza
Super User

output &sysday and see what it says then.

Tal
Pyrite | Level 9 Tal
Pyrite | Level 9

Sorry Reeza.Dont know what you mean.

@Ballard

"If you aren't closing and restarting SAS daily then you would have unexpected values.Second is to insure the proper case when comparing using equal signs"

Is it recommended that i restart my SAS daily for Macros in order to work?

Reeza
Super User

Are you running in EG or Base?

What does the log say when you run that line of code.

%put &sysday;

Tal
Pyrite | Level 9 Tal
Pyrite | Level 9

it is BASE and %put &sysday is giving me Thursday....Weird but thank you guys a lot Smiley Happy

ballardw
Super User

It's reporting the date information from the computer system clock from when the SAS session started. If you're system date isn't Thursday but you started SAS and didn't shut it down since last week you could get Thursday. Try %put &sysdate as well. If the date isn't today you have another clue.

Tal
Pyrite | Level 9 Tal
Pyrite | Level 9

ok my SAS just resolved sysday to be Thursday and  when i changed to sysday=thursday i did get results.

could this  something to do  with my PC settings ?

ballardw
Super User

One issue could be that SYSDAY has the value the SAS session started. If you aren't closing and restarting SAS daily then you would have unexpected values.Second is to insure the proper case when comparing using equal signs. When I resolved SYSDAY on my system the result was Wednesday" not the WEDNESDAY used in your code. You may want to use %upcase(&sysday)=WEDNESDAY or use the case matching SYSDAY.


Chang
Quartz | Level 8

hi,

Can any one show me why Monday does not need to be in quote as

%IF &SYSDAY = "Monday" %THEN %DO;

?


Thanks

ballardw
Super User

In the MACRO processor everything is strings. So if you are comparing a value quotes are not required, unless the value you want needs them.

This is one reason for using "&macrovariable" in data steps instead of having the macro variable include quotes.

Chang
Quartz | Level 8

can you please illustrate with examples? My understanding is that macro variables are always in quotes when used in the TITLE, FOOTNOTE statements. But when they are quoted in other statements, it becomes confusing. Thanks

ballardw
Super User

In a title or other places you would use a text literal:

%let val = Idaho;

Title " Report for &val"; which resolve to Title " Report for Idaho"; from the macro processor.

If you devine val as "Idaho" then one of two things are likely happen:

If you use

title 'Report for &val'; you don't resolve the macro variable because it is within single quotes.

If you use

title "Report for &val"; then the macro processor produces: Title "Report for "Idaho" "; and Idaho is OUTSIDE the quoted string required for title and isn't one of the acceptable options for title and will generate an error. There are ways to use the "value" definition but they get to be a lot of work, especially if you ever want to combine more than one macro variable in a statement.

In a data step:

data want;

     set have;

     if state = "&val" then do; other code.

In this example you original approach would work. But This way you can tell immediately in the code that we are expecting a text literal (and you enhanced program editor will help with that).

But suppose I want the macro variable to reference a variable name:

%let var = Total_Sales;

Data want;

     set have;

     Someothervariable = &var * 1.05;

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!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 13 replies
  • 1796 views
  • 5 likes
  • 4 in conversation