SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Tango_Mike
Fluorite | Level 6

Hello,

I am getting a Proc Means error that the variables cannot be found. (Errors in image 1). I have run the Proc Contents to verify the variable names (Image 2). I have tried running this with and without the ClassData argument.

 

CAR_10, CAR_01, etc are all variables that I would like to compute the means for (each variable's mean individually). Ideally, I would like to do this by the variable "Type" in the dataset "biotech_list" (Image3).

 

Can someone tell me what I'm doing wrong?

/* Mean CARs for all mergers */
data temp.FirmLevelCars_sort; set temp.FirmLevelCars_sort;
run;

proc means data=temp.FirmLevelCars_sort nway noprint;
	classdata=stat.biotech_list; by type;
	var car_01 car_11 car_10 car_02 car_05;
	label car_01 = '(0,1)';
	label car_11 = '(-1,1)';
	label car_10 = '(-1,0)';
	label car_02 = '(0,2)';
	label car_05 = '(0,5)';
	title 'Table 2 Panel B';
run;

image.pngimage.pngimage.png

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Here is a hint:

 

Show us the log and the results from running this code:

 

proc contents  data=temp.FirmLevelCars_sort ;
run;

proc means data=temp.FirmLevelCars_sort nway noprint;
   by type;
	var car_01 car_11 car_10 car_02 car_05;
	label car_01 = '(0,1)';
	label car_11 = '(-1,1)';
	label car_10 = '(-1,0)';
	label car_02 = '(0,2)';
	label car_05 = '(0,5)';
	title 'Table 2 Panel B';
run;

You may have had the variables in one version of the set temp.FirmLevelCars but you may have done something that removed one or more of them.

If you are learning to use SAS do not use the structure:

data temp.FirmLevelCars_sort; 
   set temp.FirmLevelCars_sort;
run;

First, that particular example does nothing except consume computer clock time. Second, when you have the same name data set on the SET and DATA statements you completely replace the data set. So some forms of logic errors can remove variables or change values and you can't ever use the original values you think are there. You would have to go back to previous steps to completely recreate the data set. While learning to use SAS you are very likely to make many logic errors.

 

 

Copy the log from the Proc contents through the proc means and show the result. Paste the copied log into a code box.

 

 

 

BTW. I suspect the Proc means you show won't run even after you remove the CLASSDATA erroneous statement as you have NOPRINT without an OUT= statement. So you have in effect told proc means not to generate anything.

View solution in original post

10 REPLIES 10
PeterClemmensen
Tourmaline | Level 20

The variable type is not present in FirmLevelCars_sort

 

Tango_Mike
Fluorite | Level 6

The CAR_xx variables are in FirmLevelCARs_sort which I want the means for (by variable). "Type" is in the dataset biotech_list. It is a categorical variable with values H or V. Although not necessary, having the CAR_xx variables split by this categorical variable would save me several future steps.

 

Sorry if my original post wasn't clear

PeterClemmensen
Tourmaline | Level 20

Be aware that Classdata is an option to the PROC MEANS Statement. As of now, you use it as a Statement of its own. See the not below

 

http://support.sas.com/kb/51/926.html

Tango_Mike
Fluorite | Level 6
Ok, thanks for that, I completely misunderstood what Classdata does (I am very new to learning SAS). I removed that line and I still get the CAR_xx variables not found. Is there an obvious reason for this or a workaround?
PeterClemmensen
Tourmaline | Level 20

The obvious reason would be that the Car_xx variables are not in the input data set 🙂 Be aware that they should be in temp.FirmLevelCars_sort;..

 

Please run

 

proc contents data=temp.FirmLevelCars_sort;
run;

and post the results.

Tango_Mike
Fluorite | Level 6

Here is the proc contents output:

image.png

ballardw
Super User

Here is a hint:

 

Show us the log and the results from running this code:

 

proc contents  data=temp.FirmLevelCars_sort ;
run;

proc means data=temp.FirmLevelCars_sort nway noprint;
   by type;
	var car_01 car_11 car_10 car_02 car_05;
	label car_01 = '(0,1)';
	label car_11 = '(-1,1)';
	label car_10 = '(-1,0)';
	label car_02 = '(0,2)';
	label car_05 = '(0,5)';
	title 'Table 2 Panel B';
run;

You may have had the variables in one version of the set temp.FirmLevelCars but you may have done something that removed one or more of them.

If you are learning to use SAS do not use the structure:

data temp.FirmLevelCars_sort; 
   set temp.FirmLevelCars_sort;
run;

First, that particular example does nothing except consume computer clock time. Second, when you have the same name data set on the SET and DATA statements you completely replace the data set. So some forms of logic errors can remove variables or change values and you can't ever use the original values you think are there. You would have to go back to previous steps to completely recreate the data set. While learning to use SAS you are very likely to make many logic errors.

 

 

Copy the log from the Proc contents through the proc means and show the result. Paste the copied log into a code box.

 

 

 

BTW. I suspect the Proc means you show won't run even after you remove the CLASSDATA erroneous statement as you have NOPRINT without an OUT= statement. So you have in effect told proc means not to generate anything.

Reeza
Super User

Do you have any errors prior to that error of variable not found? I'm guessing your data isn't sorted and that's the second error you receive and if you sort the data first then you'll be fine.

 

proc sort data=temp.firmLevelCars_sort out=firmlevelcars_sort;
by type;
run;

proc means data=FirmLevelCars_sort nway noprint;
   by type;
	var car_01 car_11 car_10 car_02 car_05;
	label car_01 = '(0,1)';
	label car_11 = '(-1,1)';
	label car_10 = '(-1,0)';
	label car_02 = '(0,2)';
	label car_05 = '(0,5)';
	title 'Table 2 Panel B';
run;

@ballardw wrote:

Here is a hint:

 

Show us the log and the results from running this code:

 

proc contents  data=temp.FirmLevelCars_sort ;
run;

proc means data=temp.FirmLevelCars_sort nway noprint;
   by type;
	var car_01 car_11 car_10 car_02 car_05;
	label car_01 = '(0,1)';
	label car_11 = '(-1,1)';
	label car_10 = '(-1,0)';
	label car_02 = '(0,2)';
	label car_05 = '(0,5)';
	title 'Table 2 Panel B';
run;

You may have had the variables in one version of the set temp.FirmLevelCars but you may have done something that removed one or more of them.

If you are learning to use SAS do not use the structure:

data temp.FirmLevelCars_sort; 
   set temp.FirmLevelCars_sort;
run;

First, that particular example does nothing except consume computer clock time. Second, when you have the same name data set on the SET and DATA statements you completely replace the data set. So some forms of logic errors can remove variables or change values and you can't ever use the original values you think are there. You would have to go back to previous steps to completely recreate the data set. While learning to use SAS you are very likely to make many logic errors.

 

 

Copy the log from the Proc contents through the proc means and show the result. Paste the copied log into a code box.

 

 

 

BTW. I suspect the Proc means you show won't run even after you remove the CLASSDATA erroneous statement as you have NOPRINT without an OUT= statement. So you have in effect told proc means not to generate anything.


 

Tango_Mike
Fluorite | Level 6
Thank you all for the help. The problem was a dataset step and then the dataset was also not sorted correctly. I appreciate the tips today!
ballardw
Super User

@Tango_Mike wrote:
Thank you all for the help. The problem was a dataset step and then the dataset was also not sorted correctly. I appreciate the tips today!

For many purposes you can use a CLASS statement instead of BY to group values. The sort is then done internally. Output data sets would however have a _type_ variable to indicate the combination of the class variables used for any output record and the TYPE or WAYS statement, NWAYS proc option or CLASSDATA data set proc option may be used to control the combinations of class variables in the output.

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

Register now!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 10 replies
  • 3540 views
  • 2 likes
  • 4 in conversation