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
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));
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;
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));
Hello @PierreYvesILY,
In addition to the other comments:
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).
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.