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 used the following code and get a bunch of errors:

 

%let Auswertungstag=%sysfunc(today());
*%let Auswertungstag = %sysevalf('01JAN2021'd);
%put &Auswertungstag.;

%let Jahr = %year(&Auswertungstag.);
%put &Jahr. ;

%let Monat = %month(&Auswertungstag.);
%put &Monat.;

data KW_DrK;
format VKW_DrK best2.;
Tag = %eval(&Auswertungstag.);
%kwdrk(&Auswertungstag.);
if KW_DrK = 1 	then VKW_DrK = 52;
				else VKW_DrK = KW_DrK - 1;
if VKW_DrK = 52 then Jahr = &Jahr.-1;
				else Jahr = &Jahr.; 
VKW_DrK = compress(VKW_DrK);
call symput('VKW_DrK',VKW_DrK);
%put &VKW_DrK.;
call symputx ('Dateiname',cats('Dr_Klein_KW_Reporting_',Jahr,'_KW',&VKW_DrK.));
call symputx('Zeitraum', cats(Jahr,'_KW',&VKW_DrK.));
run;
%put &Dateiname. &Zeitraum.;

here the logfile:

 

592        %let Auswertungstag=%sysfunc(today());
593        *%let Auswertungstag = %sysevalf('01JAN2021'd);
594        %put &Auswertungstag.;
22442
595        
596        %let Jahr = %year(&Auswertungstag.);
597        %put &Jahr. ;
2021
598        
599        %let Monat = %month(&Auswertungstag.);
600        %put &Monat.;
6
601        
602        data KW_DrK;
603        format VKW_DrK best2.;
604        Tag = %eval(&Auswertungstag.);
605        %kwdrk(&Auswertungstag.);
606        if KW_DrK = 1 	then VKW_DrK = 52;
5                                                          The SAS System                                14:11 Friday, June 11, 2021

607        				else VKW_DrK = KW_DrK - 1;
608        if VKW_DrK = 52 then Jahr = &Jahr.-1;
609        				else Jahr = &Jahr.;
610        VKW_DrK = compress(VKW_DrK);
611        call symput('VKW_DrK',VKW_DrK);
612        %put &VKW_DrK.;
WARNING: Apparent symbolic reference VKW_DRK not resolved.
&VKW_DrK.
613        call symputx ('Dateiname',cats('Dr_Klein_KW_Reporting_',Jahr,'_KW',&VKW_DrK.));
                                                                              _
                                                                              386
                                                                              200
                                                                              76
WARNING: Apparent symbolic reference VKW_DRK not resolved.
614        call symputx('Zeitraum', cats(Jahr,'_KW',&VKW_DrK.));
                                                    _
                                                    386
                                                    200
                                                    76
WARNING: Apparent symbolic reference VKW_DRK not resolved.
ERROR 386-185: Expecting an arithmetic expression.

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

ERROR 76-322: Syntax error, statement will be ignored.

615        run;

NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column).
      610:20   611:23   
NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column).
      610:11   
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.KW_DRK may be incomplete.  When this step was stopped there were 0 observations and 9 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
      

WARNING: Apparent symbolic reference DATEINAME not resolved.
WARNING: Apparent symbolic reference ZEITRAUM not resolved.
616        %put &Dateiname. &Zeitraum.;
&Dateiname. &Zeitraum.

how can I correct this?

 

regards

PY

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

Macro variable &VKW_DrK cannot be used in the same DATA step as it was created in (by CALL SYMPUTX one or two lines above).


Why do you need this to be a macro variable, anyway? A regular DATA step variable ought to work (partial code)

 

VKW_DrK = compress(VKW_DrK);
call symputx ('Dateiname',cats('Dr_Klein_KW_Reporting_',Jahr,'_KW',VKW_DrK));
--
Paige Miller

View solution in original post

5 REPLIES 5
Astounding
PROC Star

You are expecting the &VKW_DrK will be available in the same DATA step that creates it.  But that's not true,  It's not available until after the RUN statement causes the DATA step to execute.  Luckily, you already have a DATA step variable you can use instead.  Change this code:

call symput('VKW_DrK',VKW_DrK);
%put &VKW_DrK.;
call symputx ('Dateiname',cats('Dr_Klein_KW_Reporting_',Jahr,'_KW',&VKW_DrK.));
call symputx('Zeitraum', cats(Jahr,'_KW',&VKW_DrK.));
run;
%put &Dateiname. &Zeitraum.;

Instead, use:

call symput('VKW_DrK',VKW_DrK);
call symputx ('Dateiname',cats('Dr_Klein_KW_Reporting_',Jahr,'_KW',VKW_DrK));
call symputx('Zeitraum', cats(Jahr,'_KW',VKW_DrK));
run;
%put &Dateiname. &Zeitraum.;
%put &VKW_Drk;
PierreYvesILY
Pyrite | Level 9
Hallo,

I use &VKW_DrK. in the programm further, which is the reason why I need it.
Your code worked, thank you.

Have a nice WE,
Regards
PY
PaigeMiller
Diamond | Level 26

Macro variable &VKW_DrK cannot be used in the same DATA step as it was created in (by CALL SYMPUTX one or two lines above).


Why do you need this to be a macro variable, anyway? A regular DATA step variable ought to work (partial code)

 

VKW_DrK = compress(VKW_DrK);
call symputx ('Dateiname',cats('Dr_Klein_KW_Reporting_',Jahr,'_KW',VKW_DrK));
--
Paige Miller
PierreYvesILY
Pyrite | Level 9
Hallo Paige,

I use &VKW_DrK. in the programm further, which is the reason why I need it.
Your code worked, thank you.

Have a nice WE,
Regards
PY
FreelanceReinh
Jade | Level 19

Hello @PierreYvesILY,

 

In addition to the other comments:

  • Note that the %PUT statement (a macro statement, as opposed to a DATA step statement) is executed before the DATA step is compiled. So, even if a macro variable VKW_DrK existed at that point of time, its value would be written to the log in the middle of the DATA step code, but regardless of what happens during DATA step execution. In fact, it would be written to the log even if DATA step compilation failed with a syntax error that occurred before the %PUT statement. Therefore, as a rule, %PUT (and %LET) statements have their place outside of DATA steps.
  • The statement
    VKW_DrK = compress(VKW_DrK);
    would make sense for a character variable VKW_DrK, but your code suggests that this is a numeric variable. In this case the statement only produces two ugly log messages (as you see in your log, referring to line number 610) about automatic numeric-to-character conversion (in order to apply the character function COMPRESS to the initially numeric argument) and character-to-numeric conversion (in order to assign the character result from COMPRESS to the numeric variable, if possible).
  • The third type conversion mentioned in the log (referring to line 611) is caused by CALL SYMPUT, applied to a numeric second argument. Using CALL SYMPUTX instead would avoid this.

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
  • 653 views
  • 3 likes
  • 4 in conversation