Hello,
I am trying to systematically label newly created variables using the label of an old variable. When I use the call execute command, I am getting an error saying "Statement is not valid or it is used out proper order."
I used this source as reference.
%macro zscore(var=,);
proc means data = jobquality_2 noprint;
var &var.;
output out = &var._stat;
run;
*create macro var of var mean & std;
data _null_;
set &var._stat;
if _STAT_ = "MEAN" then call symputx('mean',&var.);
if _STAT_ = "STD" then call symputx('std',&var.);
run;
data &var._zscore;
set jobquality_2;
&var._m = &mean.;
&var._s = &std.;
&var._z = ((&var.-&var._m)/&var._s);
format &var.;
run;
*copy label from original var;
data &var._zscore;
set &var._zscore end=eof;
if eof then call execute ("label &var._z = "||'"'||strip(vlabel(&var.))||'";');
run;
%mend zscore;
%zscore(var=c11); 1 The SAS System 14:39 Wednesday, October 23, 2024
NOTE: Unable to open SASUSER.REGSTRY. WORK.REGSTRY will be opened instead.
NOTE: All registry changes will be lost at the end of the session.
WARNING: Unable to copy SASUSER registry to WORK registry. Because of this, you will not see registry customizations during this
session.
NOTE: Unable to open SASUSER.PROFILE. WORK.PROFILE will be opened instead.
NOTE: All profile changes will be lost at the end of the session.
NOTE: Copyright (c) 2023 by SAS Institute Inc., Cary, NC, USA.
NOTE: SAS (r) Proprietary Software 9.4 (TS1M8)
Licensed to ABT ASSOCIATES INC - SERVICE PROVIDER, Site 70213852.
NOTE: This session is executing on the X64_DSRV22 platform.
NOTE: Analytical products:
SAS/STAT 15.3
SAS/ETS 15.3
SAS/IML 15.3
NOTE: Additional host information:
X64_DSRV22 WIN 10.0.20348 Server
NOTE: SAS initialization used:
real time 4.85 seconds
cpu time 0.31 seconds
1 options nofmterr;
2
3 libname data "S:\projects\HPOG_2.0_Eval\Analysis\01 Data\Special Topics\Job Quality";
NOTE: Libref DATA was successfully assigned as follows:
Engine: V9
Physical Name: S:\projects\HPOG_2.0_Eval\Analysis\01 Data\Special Topics\Job Quality
4 libname output "S:\projects\HPOG_2.0_Eval\Analysis\04 Outputs\Special Topics\Job Quality";
NOTE: Libref OUTPUT was successfully assigned as follows:
Engine: V9
Physical Name: S:\projects\HPOG_2.0_Eval\Analysis\04 Outputs\Special Topics\Job Quality
5
6 *read in cleaned data;
7
8 data jobquality_2;
9 set data.cleaned_longterm;
10 run;
NOTE: Format YESNO was not found or could not be loaded.
NOTE: Format C2DKF was not found or could not be loaded.
NOTE: Format INDUSTRY was not found or could not be loaded.
NOTE: Format YESNO was not found or could not be loaded.
NOTE: Format C8AF was not found or could not be loaded.
NOTE: Format YESNO was not found or could not be loaded.
NOTE: Format YESNO was not found or could not be loaded.
NOTE: Format YESNO was not found or could not be loaded.
NOTE: Format C16DKF was not found or could not be loaded.
2 The SAS System 14:39 Wednesday, October 23, 2024
NOTE: Format INDUSTRY was not found or could not be loaded.
NOTE: Format YESNO was not found or could not be loaded.
NOTE: Format C26A_F was not found or could not be loaded.
NOTE: Format YESNO was not found or could not be loaded.
NOTE: Format SCHEDULE was not found or could not be loaded.
NOTE: Format SCHEDULE2_F was not found or could not be loaded.
NOTE: Format SCHEDULE3_F was not found or could not be loaded.
NOTE: Format YESNO was not found or could not be loaded.
NOTE: Format AGREE was not found or could not be loaded.
NOTE: Format AGREE was not found or could not be loaded.
NOTE: Format AGREE was not found or could not be loaded.
NOTE: Format ALOT was not found or could not be loaded.
NOTE: Format YESNO was not found or could not be loaded.
NOTE: Format YESNO was not found or could not be loaded.
NOTE: Format YESNO was not found or could not be loaded.
NOTE: Format YESNO was not found or could not be loaded.
NOTE: Format YESNO was not found or could not be loaded.
NOTE: Format YESNO was not found or could not be loaded.
NOTE: Format SATISFIED was not found or could not be loaded.
NOTE: Format AGREE was not found or could not be loaded.
NOTE: Format YESNO was not found or could not be loaded.
NOTE: Format YESNO was not found or could not be loaded.
NOTE: Format YESNO was not found or could not be loaded.
NOTE: Format YESNO was not found or could not be loaded.
NOTE: Format PROMOTIONS was not found or could not be loaded.
NOTE: Format YESNO was not found or could not be loaded.
NOTE: Format YESNO was not found or could not be loaded.
NOTE: Format YESNO was not found or could not be loaded.
NOTE: Format YESNO was not found or could not be loaded.
NOTE: Format YESNO was not found or could not be loaded.
NOTE: Format YESNO was not found or could not be loaded.
NOTE: Format YESNO was not found or could not be loaded.
NOTE: Format YESNO was not found or could not be loaded.
NOTE: Format X00001F was not found or could not be loaded.
NOTE: Format INDUSTRY was not found or could not be loaded.
NOTE: There were 1616 observations read from the data set DATA.CLEANED_LONGTERM.
NOTE: The data set WORK.JOBQUALITY_2 has 1616 observations and 59 variables.
NOTE: DATA statement used (Total process time):
real time 0.19 seconds
cpu time 0.07 seconds
11
12 *******************************************
13 *caluclate zscores for all variables;
14
15 %macro zscore(var=,);
16
17 proc means data = jobquality_2 noprint;
18 var &var.;
19 output out = &var._stat;
20 run;
21
22 *create macro var of var mean & std;
3 The SAS System 14:39 Wednesday, October 23, 2024
23 data _null_;
24 set &var._stat;
25 if _STAT_ = "MEAN" then call symputx('mean',&var.);
26 if _STAT_ = "STD" then call symputx('std',&var.);
27 run;
28
29 data &var._zscore;
30 set jobquality_2;
31 &var._m = &mean.;
32 &var._s = &std.;
33 &var._z = ((&var.-&var._m)/&var._s);
34 format &var.;
35 run;
36
37 *copy label from original var;
38 data &var._zscore;
39 set &var._zscore end=eof;
40 if eof then call execute ("label &var._z = "||'"'||strip(vlabel(&var.))||'";');
41 run;
42
43 %mend zscore;
44
45 %zscore(var=c11);
NOTE: There were 1616 observations read from the data set WORK.JOBQUALITY_2.
NOTE: The data set WORK.C11_STAT has 5 observations and 4 variables.
NOTE: PROCEDURE MEANS used (Total process time):
real time 0.10 seconds
cpu time 0.03 seconds
NOTE: There were 5 observations read from the data set WORK.C11_STAT.
NOTE: DATA statement used (Total process time):
real time 0.03 seconds
cpu time 0.00 seconds
NOTE: Format YESNO was not found or could not be loaded.
NOTE: Format C2DKF was not found or could not be loaded.
NOTE: Format INDUSTRY was not found or could not be loaded.
NOTE: Format YESNO was not found or could not be loaded.
NOTE: Format C8AF was not found or could not be loaded.
NOTE: Format YESNO was not found or could not be loaded.
NOTE: Format YESNO was not found or could not be loaded.
NOTE: Format YESNO was not found or could not be loaded.
NOTE: Format C16DKF was not found or could not be loaded.
NOTE: Format INDUSTRY was not found or could not be loaded.
NOTE: Format YESNO was not found or could not be loaded.
NOTE: Format C26A_F was not found or could not be loaded.
NOTE: Format YESNO was not found or could not be loaded.
NOTE: Format SCHEDULE was not found or could not be loaded.
NOTE: Format SCHEDULE2_F was not found or could not be loaded.
4 The SAS System 14:39 Wednesday, October 23, 2024
NOTE: Format SCHEDULE3_F was not found or could not be loaded.
NOTE: Format YESNO was not found or could not be loaded.
NOTE: Format AGREE was not found or could not be loaded.
NOTE: Format AGREE was not found or could not be loaded.
NOTE: Format AGREE was not found or could not be loaded.
NOTE: Format ALOT was not found or could not be loaded.
NOTE: Format YESNO was not found or could not be loaded.
NOTE: Format YESNO was not found or could not be loaded.
NOTE: Format YESNO was not found or could not be loaded.
NOTE: Format YESNO was not found or could not be loaded.
NOTE: Format YESNO was not found or could not be loaded.
NOTE: Format YESNO was not found or could not be loaded.
NOTE: Format SATISFIED was not found or could not be loaded.
NOTE: Format AGREE was not found or could not be loaded.
NOTE: Format YESNO was not found or could not be loaded.
NOTE: Format YESNO was not found or could not be loaded.
NOTE: Format YESNO was not found or could not be loaded.
NOTE: Format YESNO was not found or could not be loaded.
NOTE: Format PROMOTIONS was not found or could not be loaded.
NOTE: Format YESNO was not found or could not be loaded.
NOTE: Format YESNO was not found or could not be loaded.
NOTE: Format YESNO was not found or could not be loaded.
NOTE: Format YESNO was not found or could not be loaded.
NOTE: Format YESNO was not found or could not be loaded.
NOTE: Format YESNO was not found or could not be loaded.
NOTE: Format YESNO was not found or could not be loaded.
NOTE: Format YESNO was not found or could not be loaded.
NOTE: Format X00001F was not found or could not be loaded.
NOTE: Format INDUSTRY was not found or could not be loaded.
NOTE: Missing values were generated as a result of performing an operation on missing values.
Each place is given by: (Number of times) at (Line):(Column).
1545 at 61:120
NOTE: There were 1616 observations read from the data set WORK.JOBQUALITY_2.
NOTE: The data set WORK.C11_ZSCORE has 1616 observations and 62 variables.
NOTE: DATA statement used (Total process time):
real time 0.03 seconds
cpu time 0.03 seconds
NOTE: Format YESNO was not found or could not be loaded.
NOTE: Format C2DKF was not found or could not be loaded.
NOTE: Format INDUSTRY was not found or could not be loaded.
NOTE: Format YESNO was not found or could not be loaded.
NOTE: Format C8AF was not found or could not be loaded.
NOTE: Format YESNO was not found or could not be loaded.
NOTE: Format YESNO was not found or could not be loaded.
NOTE: Format YESNO was not found or could not be loaded.
NOTE: Format C16DKF was not found or could not be loaded.
NOTE: Format INDUSTRY was not found or could not be loaded.
NOTE: Format YESNO was not found or could not be loaded.
NOTE: Format C26A_F was not found or could not be loaded.
NOTE: Format YESNO was not found or could not be loaded.
NOTE: Format SCHEDULE was not found or could not be loaded.
5 The SAS System 14:39 Wednesday, October 23, 2024
NOTE: Format SCHEDULE2_F was not found or could not be loaded.
NOTE: Format SCHEDULE3_F was not found or could not be loaded.
NOTE: Format YESNO was not found or could not be loaded.
NOTE: Format AGREE was not found or could not be loaded.
NOTE: Format AGREE was not found or could not be loaded.
NOTE: Format AGREE was not found or could not be loaded.
NOTE: Format ALOT was not found or could not be loaded.
NOTE: Format YESNO was not found or could not be loaded.
NOTE: Format YESNO was not found or could not be loaded.
NOTE: Format YESNO was not found or could not be loaded.
NOTE: Format YESNO was not found or could not be loaded.
NOTE: Format YESNO was not found or could not be loaded.
NOTE: Format YESNO was not found or could not be loaded.
NOTE: Format SATISFIED was not found or could not be loaded.
NOTE: Format AGREE was not found or could not be loaded.
NOTE: Format YESNO was not found or could not be loaded.
NOTE: Format YESNO was not found or could not be loaded.
NOTE: Format YESNO was not found or could not be loaded.
NOTE: Format YESNO was not found or could not be loaded.
NOTE: Format PROMOTIONS was not found or could not be loaded.
NOTE: Format YESNO was not found or could not be loaded.
NOTE: Format YESNO was not found or could not be loaded.
NOTE: Format YESNO was not found or could not be loaded.
NOTE: Format YESNO was not found or could not be loaded.
NOTE: Format YESNO was not found or could not be loaded.
NOTE: Format YESNO was not found or could not be loaded.
NOTE: Format YESNO was not found or could not be loaded.
NOTE: Format YESNO was not found or could not be loaded.
NOTE: Format X00001F was not found or could not be loaded.
NOTE: Format INDUSTRY was not found or could not be loaded.
NOTE: There were 1616 observations read from the data set WORK.C11_ZSCORE.
NOTE: The data set WORK.C11_ZSCORE has 1616 observations and 62 variables.
NOTE: DATA statement used (Total process time):
real time 0.05 seconds
cpu time 0.03 seconds
NOTE: CALL EXECUTE generated line.
NOTE: Line generated by the CALL EXECUTE routine.
1 + label c11_z = "C11. About how much did you typically earn per hour before taxes?";
_____
180
ERROR 180-322: Statement is not valid or it is used out of proper order.
46 %zscore(var=c11a);
NOTE: The SAS System stopped processing this step because of errors.
NOTE: Due to ERROR(s) above, SAS set option OBS=0, enabling syntax check mode.
This prevents execution of subsequent data modification statements.
WARNING: The data set WORK.C11A_STAT may be incomplete. When this step was stopped there were 0
observations and 0 variables.
NOTE: PROCEDURE MEANS used (Total process time):
real time 0.00 seconds
6 The SAS System 14:39 Wednesday, October 23, 2024
cpu time 0.01 seconds
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
386: LINE and COLUMN cannot be determined.
NOTE: NOSPOOL is on. Rerunning with OPTION SPOOL might allow recovery of the LINE and COLUMN where
the error has occurred.
ERROR 386-185: Expecting an arithmetic expression.
200: LINE and COLUMN cannot be determined.
NOTE: NOSPOOL is on. Rerunning with OPTION SPOOL might allow recovery of the LINE and COLUMN where
the error has occurred.
ERROR 200-322: The symbol is not recognized and will be ignored.
WARNING: Apparent symbolic reference MEAN not resolved.
386: LINE and COLUMN cannot be determined.
NOTE: NOSPOOL is on. Rerunning with OPTION SPOOL might allow recovery of the LINE and COLUMN where
the error has occurred.
ERROR 386-185: Expecting an arithmetic expression.
200: LINE and COLUMN cannot be determined.
NOTE: NOSPOOL is on. Rerunning with OPTION SPOOL might allow recovery of the LINE and COLUMN where
the error has occurred.
ERROR 200-322: The symbol is not recognized and will be ignored.
WARNING: Apparent symbolic reference STD not resolved.
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.C11A_ZSCORE may be incomplete. When this step was stopped there were 0
observations and 62 variables.
NOTE: DATA statement used (Total process time):
real time 0.02 seconds
cpu time 0.00 seconds
NOTE: The data set WORK.C11A_ZSCORE has 0 observations and 62 variables.
WARNING: Data set WORK.C11A_ZSCORE 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
47 %zscore(var=c13);
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.C13_STAT may be incomplete. When this step was stopped there were 0
observations and 0 variables.
NOTE: PROCEDURE MEANS used (Total process time):
real time 0.00 seconds
cpu time 0.01 seconds
7 The SAS System 14:39 Wednesday, October 23, 2024
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
386: LINE and COLUMN cannot be determined.
NOTE: NOSPOOL is on. Rerunning with OPTION SPOOL might allow recovery of the LINE and COLUMN where
the error has occurred.
ERROR 386-185: Expecting an arithmetic expression.
200: LINE and COLUMN cannot be determined.
NOTE: NOSPOOL is on. Rerunning with OPTION SPOOL might allow recovery of the LINE and COLUMN where
the error has occurred.
ERROR 200-322: The symbol is not recognized and will be ignored.
WARNING: Apparent symbolic reference MEAN not resolved.
386: LINE and COLUMN cannot be determined.
NOTE: NOSPOOL is on. Rerunning with OPTION SPOOL might allow recovery of the LINE and COLUMN where
the error has occurred.
ERROR 386-185: Expecting an arithmetic expression.
200: LINE and COLUMN cannot be determined.
NOTE: NOSPOOL is on. Rerunning with OPTION SPOOL might allow recovery of the LINE and COLUMN where
the error has occurred.
ERROR 200-322: The symbol is not recognized and will be ignored.
WARNING: Apparent symbolic reference STD not resolved.
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.C13_ZSCORE may be incomplete. When this step was stopped there were 0
observations and 62 variables.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
NOTE: The data set WORK.C13_ZSCORE has 0 observations and 62 variables.
WARNING: Data set WORK.C13_ZSCORE 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
48 %zscore(var=c18);
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.C18_STAT may be incomplete. When this step was stopped there were 0
observations and 0 variables.
NOTE: PROCEDURE MEANS used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
8 The SAS System 14:39 Wednesday, October 23, 2024
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.01 seconds
386: LINE and COLUMN cannot be determined.
NOTE: NOSPOOL is on. Rerunning with OPTION SPOOL might allow recovery of the LINE and COLUMN where
the error has occurred.
ERROR 386-185: Expecting an arithmetic expression.
200: LINE and COLUMN cannot be determined.
NOTE: NOSPOOL is on. Rerunning with OPTION SPOOL might allow recovery of the LINE and COLUMN where
the error has occurred.
ERROR 200-322: The symbol is not recognized and will be ignored.
WARNING: Apparent symbolic reference MEAN not resolved.
386: LINE and COLUMN cannot be determined.
NOTE: NOSPOOL is on. Rerunning with OPTION SPOOL might allow recovery of the LINE and COLUMN where
the error has occurred.
ERROR 386-185: Expecting an arithmetic expression.
200: LINE and COLUMN cannot be determined.
NOTE: NOSPOOL is on. Rerunning with OPTION SPOOL might allow recovery of the LINE and COLUMN where
the error has occurred.
ERROR 200-322: The symbol is not recognized and will be ignored.
WARNING: Apparent symbolic reference STD not resolved.
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.C18_ZSCORE may be incomplete. When this step was stopped there were 0
observations and 62 variables.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
NOTE: The data set WORK.C18_ZSCORE has 0 observations and 62 variables.
WARNING: Data set WORK.C18_ZSCORE 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
49 %zscore(var=c18a);
ERROR: Variable C18A not found.
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.C18A_STAT may be incomplete. When this step was stopped there were 0
observations and 0 variables.
NOTE: PROCEDURE MEANS used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
NOTE: DATA statement used (Total process time):
9 The SAS System 14:39 Wednesday, October 23, 2024
real time 0.00 seconds
cpu time 0.00 seconds
386: LINE and COLUMN cannot be determined.
NOTE: NOSPOOL is on. Rerunning with OPTION SPOOL might allow recovery of the LINE and COLUMN where
the error has occurred.
ERROR 386-185: Expecting an arithmetic expression.
200: LINE and COLUMN cannot be determined.
NOTE: NOSPOOL is on. Rerunning with OPTION SPOOL might allow recovery of the LINE and COLUMN where
the error has occurred.
ERROR 200-322: The symbol is not recognized and will be ignored.
WARNING: Apparent symbolic reference MEAN not resolved.
386: LINE and COLUMN cannot be determined.
NOTE: NOSPOOL is on. Rerunning with OPTION SPOOL might allow recovery of the LINE and COLUMN where
the error has occurred.
ERROR 386-185: Expecting an arithmetic expression.
200: LINE and COLUMN cannot be determined.
NOTE: NOSPOOL is on. Rerunning with OPTION SPOOL might allow recovery of the LINE and COLUMN where
the error has occurred.
ERROR 200-322: The symbol is not recognized and will be ignored.
WARNING: Apparent symbolic reference STD not resolved.
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.C18A_ZSCORE may be incomplete. When this step was stopped there were 0
observations and 63 variables.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
NOTE: The data set WORK.C18A_ZSCORE has 0 observations and 63 variables.
WARNING: Data set WORK.C18A_ZSCORE 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
ERROR: Errors printed on pages 5,6,7,8,9.
NOTE: SAS Institute Inc., SAS Campus Drive, Cary, NC USA 27513-2414
NOTE: The SAS System used:
real time 5.64 seconds
cpu time 0.56 seconds
CALL EXECUTE works after the data step it is in finishes. So ... LABEL statement outside of a DATA step or PROC is not allowed.
Don't use CALL EXECUTE here, just include the LABEL statement in the DATA step.
I point out that looping through variables one variable at a time in a macro is an extremely inefficient way of doing most things. Better to figure out how to handle all variables in one pass. Storing means and standard deviations in a macro variable is unnecessary.
EVEN BETTER APPROACH
SAS has an extremely wide ranging set of PROCs to perform statistical and other analyses, you should try to find a PROC that does what you want before resorting to macros. I see you performing a standard statistical calculation like this (which is called standardizing):
&var._z = ((&var.-&var._m)/&var._s);
Surely there is a PROC that will standardize your variables! In fact there is a PROC, it is called PROC STDIZE. The entire macro and all the looping is unnecessary.
So except for your label statement, none of this looping or macro is necessary, and this ought to get you what you want.
proc stdize data=jobquality_2 method=std out=jobquality_2z oprefix=o_ sprefix=z_;
var c1-c31; /* or whatever the variable names are */
run;
so your standardized values and original values are now in data set jobquality_2z
Adding: Using PROC STDIZE, the new standardzied variables automatically get the same label as the original variables.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.