214
215
216 %macro rl_all(d,k);
217
218 data &k._&d.;
219 set r_&k.;
220 filename tmp temp;
221 data _null_;
222 if 0 then set &k._&d.;
223 length _vname $60;
224 file tmp;
225 put 'rename ' @;
226 do i=1 by 1 until (upcase(_vname)='_VNAME');
227 call vnext(_vname);
228 if upcase(_vname)='_VNAME' then leave;
229 put _vname +(-1) '=V' i @;
230 end;
231 put ';';
232 run;
233 proc datasets library=work nolist;
234 modify &k._&d.;
235 %include tmp / source2;
236 run;
237 quit;
238
239 ods select none;
240
241 proc append
242 data=&k._&d.
243 base= n_all_&d.
244 force
245 ;
246 run;
247
248 %mend;
249 %if %sysfunc(exist(n_all_&d.))
WARNING: Apparent symbolic reference D not resolved.
250 %then %do;
251 proc delete data=n_all_&d.;
252 run;
253 %end;
254 %rl_all(mat_1,Group);
NOTE: There were 2 observations read from the data set WORK.R_GROUP.
NOTE: The data set WORK.GROUP_MAT_1 has 2 observations and 3 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds
NOTE: The file TMP is:
Filename=C:\Users\dd~1\AppData\Local\Temp\SAS Temporary Files\_TD17280_VM-05_\#LN00058,
RECFM=V,LRECL=32767,File Size (bytes)=0,
Last Modified=21Jun2022:16:34:54,
Create Time=21Jun2022:16:34:54
NOTE: DATA STEP stopped due to looping.
NOTE: 1 record was written to the file TMP.
The minimum record length was 39.
The maximum record length was 39.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
NOTE: %INCLUDE (level 1) file TMP is file C:\Users\dd~1\AppData\Local\Temp\SAS Temporary
Files\_TD17280_VM-05_\#LN00058.
255 +rename Group=V1 Variables=V2 Alpha=V3 ;
NOTE: Renaming variable Group to V1.
NOTE: Renaming variable Variables to V2.
NOTE: Renaming variable Alpha to V3.
NOTE: %INCLUDE (level 1) ending.
NOTE: MODIFY was successful for WORK.GROUP_MAT_1.DATA.
NOTE: PROCEDURE DATASETS used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds
NOTE: Appending WORK.GROUP_MAT_1 to WORK.N_ALL_MAT_1.
NOTE: There were 2 observations read from the data set WORK.GROUP_MAT_1.
NOTE: 2 observations added.
NOTE: The data set WORK.N_ALL_MAT_1 has 74 observations and 3 variables.
NOTE: PROCEDURE APPEND used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds
256 %rl_all(mat_1,gender_n);
NOTE: There were 6 observations read from the data set WORK.R_GENDER_N.
NOTE: The data set WORK.GENDER_N_MAT_1 has 6 observations and 3 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds
NOTE: The file TMP is:
Filename=C:\Users\dd~1\AppData\Local\Temp\SAS Temporary Files\_TD17280_VM-05_\#LN00059,
RECFM=V,LRECL=32767,File Size (bytes)=0,
Last Modified=21Jun2022:16:34:54,
Create Time=21Jun2022:16:34:54
NOTE: DATA STEP stopped due to looping.
NOTE: 1 record was written to the file TMP.
The minimum record length was 42.
The maximum record length was 42.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds
NOTE: %INCLUDE (level 1) file TMP is file C:\Users\dd~1\AppData\Local\Temp\SAS Temporary
Files\_TD17280_VM-05_\#LN00059.
257 +rename gender_n=V1 Variables=V2 Alpha=V3 ;
NOTE: Renaming variable gender_n to V1.
NOTE: Renaming variable Variables to V2.
NOTE: Renaming variable Alpha to V3.
NOTE: %INCLUDE (level 1) ending.
NOTE: MODIFY was successful for WORK.GENDER_N_MAT_1.DATA.
NOTE: PROCEDURE DATASETS used (Total process time):
real time 0.01 seconds
cpu time 0.00 seconds
NOTE: Appending WORK.GENDER_N_MAT_1 to WORK.N_ALL_MAT_1.
WARNING: Variable V1 has different lengths on BASE and DATA files (BASE 12 DATA 6).
NOTE: There were 6 observations read from the data set WORK.GENDER_N_MAT_1.
NOTE: 6 observations added.
NOTE: The data set WORK.N_ALL_MAT_1 has 80 observations and 3 variables.
NOTE: PROCEDURE APPEND used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds
258 %rl_all(mat_1,ethnicity_f);
NOTE: There were 16 observations read from the data set WORK.R_ETHNICITY_F.
NOTE: The data set WORK.ETHNICITY_F_MAT_1 has 16 observations and 3 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds
NOTE: The file TMP is:
Filename=C:\Users\dd~1\AppData\Local\Temp\SAS Temporary Files\_TD17280_VM-05_\#LN00060,
RECFM=V,LRECL=32767,File Size (bytes)=0,
Last Modified=21Jun2022:16:34:54,
Create Time=21Jun2022:16:34:54
NOTE: DATA STEP stopped due to looping.
NOTE: 1 record was written to the file TMP.
The minimum record length was 45.
The maximum record length was 45.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds
NOTE: %INCLUDE (level 1) file TMP is file C:\Users\dd~1\AppData\Local\Temp\SAS Temporary
Files\_TD17280_VM-05_\#LN00060.
259 +rename ethnicity_f=V1 Variables=V2 Alpha=V3 ;
NOTE: Renaming variable ethnicity_f to V1.
NOTE: Renaming variable Variables to V2.
NOTE: Renaming variable Alpha to V3.
NOTE: %INCLUDE (level 1) ending.
NOTE: MODIFY was successful for WORK.ETHNICITY_F_MAT_1.DATA.
NOTE: PROCEDURE DATASETS used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds
NOTE: Appending WORK.ETHNICITY_F_MAT_1 to WORK.N_ALL_MAT_1.
WARNING: Variable V1 has different lengths on BASE and DATA files (BASE 12 DATA 50).
NOTE: FORCE is specified, so dropping/truncating will occur.
NOTE: There were 16 observations read from the data set WORK.ETHNICITY_F_MAT_1.
NOTE: 16 observations added.
NOTE: The data set WORK.N_ALL_MAT_1 has 96 observations and 3 variables.
NOTE: PROCEDURE APPEND used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
hi,
it is such a long way and i am sure there is an easy way to do it. I am trying to put Cronbach alpha results together. Since the first variable name is different in each table "set" statement did not work. So i decided to change variables' name and then put them together. However it did not work. i am getting some errors. I think the last part is not working.
If there is an easier way to do that you are more than welcome to suggest a new code. Or could you please help me to find out why this code is not working?
Edit: I also added the log for the error
Thanks
%macro rl_all(d,k);
proc sort data=tr2_rlb_&d.;
by &k.;
run;
proc corr data = tr2_rlb_&d. alpha nocorr nomiss;
VAR V:;
ods output CronbachAlpha= r_&k.;
by &k.;
run;
data &k._&d.;
set r_&k.;
filename tmp temp;
data _null_;
if 0 then set &k._&d.;
length _vname $60;
file tmp;
put 'rename ' @;
do i=1 by 1 until (upcase(_vname)='_VNAME');
call vnext(_vname);
if upcase(_vname)='_VNAME' then leave;
put _vname +(-1) '=V' i @;
end;
put ';';
run;
proc datasets library=work nolist;
modify &k._&d.;
%include tmp / source2;
run;
quit;
ods select none;
proc append
data=&k._&d.
base= n_all_&d.
force
;
run;
%mend;
%if %sysfunc(exist(n_all_&d.))
%then %do;
proc delete data=n_all_&d.;
run;
%end;
%rl_all(mat_1,Group);
%rl_all(mat_1,gender_n);
%rl_all(mat_1,ethnicity_f);
Specifically, the code posted doesn't match the log posted. For example, there's no proc corr or sort in the macro definition in the code run but the code shown does have one. It also really helps to format your code.
%macro rl_all(d, k);
proc sort data=tr2_rlb_&d.;
by &k.;
run;
proc corr data=tr2_rlb_&d. alpha nocorr nomiss;
VAR V:;
ods output CronbachAlpha=r_&k.;
by &k.;
run;
data &k._&d.;
set r_&k.;
filename tmp temp;
data _null_;
if 0 then
set &k._&d.;
length _vname $60;
file tmp;
put 'rename ' @;
do i=1 by 1 until (upcase(_vname)='_VNAME');
call vnext(_vname);
if upcase(_vname)='_VNAME' then
leave;
put _vname +(-1) '=V' i @;
end;
put ';';
run;
proc datasets library=work nolist;
modify &k._&d.;
%include tmp / source2;
run;
quit;
ods select none;
proc append data=&k._&d.
base=n_all_&d.
force;
run;
%mend;
%if %sysfunc(exist(n_all_&d.)) %then %do;
proc delete data=n_all_&d.;
run;
%end;
%rl_all(mat_1, Group);
%rl_all(mat_1, gender_n);
%rl_all(mat_1, ethnicity_f);
Whenever SAS shows errors, you need to show us the LOG. No exceptions from now on! We need to see the entire LOG for this macro, every single line, every single character, 100% of it. We need you to first turn on macro debugging tools
options mprint;
Next, run the code again, copy the ENTIRE log for this macro, and paste it into the window that appears when you click on the </> icon.
Large economy sized hint: when you get errors include the code with the errors from the log. Otherwise we are guessing what errors you are getting. When the code involves macros then set OPTIONS MPRINT ; before executing the macro so the notes and errors appear in better relation to the generated statements?
Did you have this code working without any macro attempt before creating the macro?
You don't provide anything that really clears up what this means: "Since the first variable name is different in each table "set" statement did not work."
I guess that maybe the WITH statement coupled with the VAR might be of interest but without any example data, or actual description of what is going on it is hard to guess. Without your data there is no way to tell why your code doesn't work. With the LOG we might have some places to look.
Specifically, the code posted doesn't match the log posted. For example, there's no proc corr or sort in the macro definition in the code run but the code shown does have one. It also really helps to format your code.
%macro rl_all(d, k);
proc sort data=tr2_rlb_&d.;
by &k.;
run;
proc corr data=tr2_rlb_&d. alpha nocorr nomiss;
VAR V:;
ods output CronbachAlpha=r_&k.;
by &k.;
run;
data &k._&d.;
set r_&k.;
filename tmp temp;
data _null_;
if 0 then
set &k._&d.;
length _vname $60;
file tmp;
put 'rename ' @;
do i=1 by 1 until (upcase(_vname)='_VNAME');
call vnext(_vname);
if upcase(_vname)='_VNAME' then
leave;
put _vname +(-1) '=V' i @;
end;
put ';';
run;
proc datasets library=work nolist;
modify &k._&d.;
%include tmp / source2;
run;
quit;
ods select none;
proc append data=&k._&d.
base=n_all_&d.
force;
run;
%mend;
%if %sysfunc(exist(n_all_&d.)) %then %do;
proc delete data=n_all_&d.;
run;
%end;
%rl_all(mat_1, Group);
%rl_all(mat_1, gender_n);
%rl_all(mat_1, ethnicity_f);
@dustychair wrote:it is such a long way and i am sure there is an easy way to do it. I am trying to put Cronbach alpha results together. Since the first variable name is different in each table "set" statement did not work. So i decided to change variables' name and then put them together. However it did not work. i am getting some errors. I think the last part is not working.
If there is an easier way to do that you are more than welcome to suggest a new code. Or could you please help me to find out why this code is not working?
Edit: I also added the log for the error
Thanks
Yup, you were definitely trying to do this the hard way. No idea why you tried to change the name of the variable in that method instead of a simple rename statement. I would add two variables, one for the variable value and one for the variable of interest.
%macro rl_all(d, k);
proc sort data=tr2_rlb_&d.;
by &k.;
run;
proc corr data=tr2_rlb_&d. alpha nocorr nomiss;
by &k.;
VAR V:;
ods output CronbachAlpha=r_&k. (rename= &k = VariableValue);
run;
data &k._&d.;
length variable $32. VariableValue $50.;
set r_&k.;
variable = "&k";
run;
proc append data=&k._&d. base=n_all_&d. force;
run;
%mend;
%if %sysfunc(exist(n_all_&d.)) %then %do;
proc delete data=n_all_&d.;
run;
%end;
%rl_all(mat_1, Group);
%rl_all(mat_1, gender_n);
%rl_all(mat_1, ethnicity_f);
@dustychair I see you have added the log but you neglected to run this command. Please run this command and then show us the log as described.
We need you to first turn on macro debugging tools:
options mprint;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.