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

dear SAS experts,

 

I have this:

* Jahr1 = aktuelles Jahr, Jahr2 = Vorjahr ;

%let Jahr1=%year(&Auswertungstag.);

%let Jahr2=%eval(&Jahr1.-1);

%put &Jahr1.;

%put &Jahr2.;

data ORB_Select_&Jahr2.;

set MUC_PROD.ORB_&Jahr2. (keep= ZSRID ANZAHL MONAT KW PLATTFORM MBRBEZ_BT MARKTREGION_BT

 

NLBEZ_BT MR_KOMPAKT_BT);

jahr=&Jahr2.;

run;

data ORB_Select_&Jahr1.;

set MUC_PROD.ORB_&Jahr1. (keep= ZSRID ANZAHL MONAT KW PLATTFORM MBRBEZ_BT MARKTREGION_BT

 

NLBEZ_BT MR_KOMPAKT_BT);

jahr=&Jahr1.;

run;

 

I get the following errors:

 

25 GOPTIONS ACCESSIBLE;

26 data ORB_Select_&Jahr2.;

27 set MUC_PROD.ORB_&Jahr2. (keep= ZSRID ANZAHL MONAT KW PLATTFORM MBRBEZ_BT MARKTREGION_BT

28 NLBEZ_BT MR_KOMPAKT_BT);

29 jahr=&Jahr2.;

30 run;

NOTE: There were 410737 observations read from the data set MUC_PROD.ORB_2020.

NOTE: The data set WORK.ORB_SELECT_2020 has 410737 observations and 10 variables.

NOTE: Compressing data set WORK.ORB_SELECT_2020 decreased size by 42.23 percent.

Compressed is 669 pages; un-compressed would require 1158 pages.

NOTE: DATA statement used (Total process time):

real time 1.74 seconds

cpu time 0.75 seconds

 

31 data ORB_Select_&Jahr1.;

NOTE: Line generated by the macro variable "JAHR1".

31 ORB_Select_2021

____

22

____

200

ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, (, /, ;, _DATA_, _LAST_, _NULL_.

ERROR 200-322: The symbol is not recognized and will be ignored.

32 set MUC_PROD.ORB_&Jahr1. (keep= ZSRID ANZAHL MONAT KW PLATTFORM MBRBEZ_BT MARKTREGION_BT

NOTE: Line generated by the macro variable "JAHR1".

32 MUC_PROD.ORB_2021

____

22

____

2 The SAS System 09:12 Friday, February 26, 2021

200

ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, (, -, :, ;, CUROBS, END, INDSNAME, KEY,

KEYRESET, KEYS, NOBS, OPEN, POINT, _DATA_, _LAST_, _NULL_.

ERROR 200-322: The symbol is not recognized and will be ignored.

33 NLBEZ_BT MR_KOMPAKT_BT);

ERROR: File MUC_PROD.ORB_.DATA does not exist.

ERROR: The metadata for the table/view MUC_PROD.ORB_ does not exist.

34 jahr=&Jahr1.;

35 run;

NOTE: Compression was disabled for data set WORK.ORB_SELECT_ because compression overhead would increase the size of the data set.

NOTE: The SAS System stopped processing this step because of errors.

WARNING: The data set WORK.ORB_SELECT_ may be incomplete. When this step was stopped there were 0 observations and 1 variables.

WARNING: Data set WORK.ORB_SELECT_ was not replaced because this step was stopped.

NOTE: DATA statement used (Total process time):

real time 0.00 seconds

cpu time 0.00 seconds

 

 

I can't understand what's wrong, as the datastep text is exactly the same and works for the first one.

 

How can I correct this?

 

thx in advance

regards

PY

 

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

If the %YEAR macro does nothing else than the data step YEAR function, then I would (for reasons of maintainability) always use the data step function with %sysfunc.

The same holds true for every case where there already is a SAS function available.

And IF you absolutely want to shorten your typing, the %YEAR macro should be defined like this:

%let auswertungstag = %sysfunc(today());

%macro year(datum);
%sysfunc(year(&datum.));
%mend;

%let jahr1 = %year(&auswertungstag.);

data test&jahr1.;
set sashelp.class;
run;

No fancy processing, no quoting.

View solution in original post

5 REPLIES 5
Shmuel
Garnet | Level 18

I assume %year is a predefined macro, unknown to me.

What is the result of next test code:

%let Jahr1=%year(&Auswertungstag.);
%put *&Jahr1*

are there blanks or special characters in the PUT result?

 

FreelanceReinh
Jade | Level 19

Hello @PierreYvesILY,

 

To me this looks like a macro quoting issue.

 

Change the definition of macro variable Jahr1 to

%let Jahr1=%unquote(%year(&Auswertungstag.));
Kurt_Bremser
Super User

%YEAR is not a standard SAS macro function, so it is of interest to see the code of that macro.

But why don't you use the SAS function (assuming AUSWERTUNGSTAG contains a SAS date value)?

%let auswertungstag=%sysfunc(today());
%let jahr1=%sysfunc(year(&auswertungstag.));
%put &=jahr1.;

data ORB_Select_&Jahr1.;
set sashelp.class;
run;

Log:

 73         %let auswertungstag=%sysfunc(today());
 74         %let jahr1=%sysfunc(year(&auswertungstag.));
 75         %put &=jahr1.;
 JAHR1=2021
 76         
 77         data ORB_Select_&Jahr1.;
 78         set sashelp.class;
 79         run;
 
 NOTE: There were 19 observations read from the data set SASHELP.CLASS.
 NOTE: The data set WORK.ORB_SELECT_2021 has 19 observations and 5 variables.
 NOTE:  Verwendet wurde: DATA statement - (Gesamtverarbeitungszeit):
       real time           0.01 seconds
       cpu time            0.01 seconds
PierreYvesILY
Pyrite | Level 9

I actually solved the problem writing this:

 

* Jahr1 = aktuelles Jahr, Jahr2 = Vorjahr ;

%let Jahr1=%eval(%year(&Auswertungstag.));

%let Jahr2=%eval(&Jahr1.-1);

%put &Jahr1.;

%put &Jahr2.;

 

I don't know if it's worse than the solutions you proposed.

 

Kurt_Bremser
Super User

If the %YEAR macro does nothing else than the data step YEAR function, then I would (for reasons of maintainability) always use the data step function with %sysfunc.

The same holds true for every case where there already is a SAS function available.

And IF you absolutely want to shorten your typing, the %YEAR macro should be defined like this:

%let auswertungstag = %sysfunc(today());

%macro year(datum);
%sysfunc(year(&datum.));
%mend;

%let jahr1 = %year(&auswertungstag.);

data test&jahr1.;
set sashelp.class;
run;

No fancy processing, no quoting.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 5 replies
  • 608 views
  • 4 likes
  • 4 in conversation