BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
dustychair
Pyrite | Level 9
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);

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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);

 

 

View solution in original post

5 REPLIES 5
PaigeMiller
Diamond | Level 26

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.

2021-11-26 08_27_29-Reply to Message - SAS Support Communities — Mozilla Firefox.png

--
Paige Miller
ballardw
Super User

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.

Reeza
Super User

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);

 

 

Reeza
Super User

@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);
PaigeMiller
Diamond | Level 26

@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;

 

 

--
Paige Miller

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 539 views
  • 1 like
  • 4 in conversation