Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Home
- /
- Programming
- /
- Programming
- /
- Proc Means Variable not found

Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

🔒 This topic is **solved** and **locked**.
Need further help from the community? Please
sign in and ask a **new** question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Posted 10-15-2019 07:07 AM
(2382 views)

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

1 ACCEPTED SOLUTION

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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.

10 REPLIES 10

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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?

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Here is the proc contents output:

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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 notuse 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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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!

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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

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

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.