BookmarkSubscribeRSS Feed
tpage
Fluorite | Level 6

I am having trouble performing simple mathematical operations with SASHELP.class data. I am trying to subtract one pound from all of the classmates' weights, but an error message comes up reading "ERROR: User does not have appropriate authorization level for library SASHELP." Below is the code that I am currently using. I have also transposed the data, so I would like the results to be transposed as well.

 

 

PROC EXPORT data=sashelp.class
outfile=_dataout
dbms=dlm replace; run;

PROC CONTENTS data=sashelp.class; RUN;

PROC TRANSPOSE data=sashelp.class
OUT=class_transposed; RUN;

PROC REPORT data=class_transposed; RUN;

DATA sashelp.class;
set class_transposed;
Weight = Weight - 1;
RUN;

 

 

I also tried to perform the operation of subtracting one pound from all the weights in a data step with the variables "_NAME_" and "Weight" using IF THEN statements, but that didn't work either. 

 

Does anyone know how I can use data from sashelp and perform simple arithmetic operations without having the "authorization" error pop up? Thanks in advance.

 

6 REPLIES 6
Tom
Super User Tom
Super User

Can you please provide some comments for what you think the statements you posted are doing? That way we can help you understand better.

 

If you want to do calculations using a variable you need use a variable that exists. Otherwise SAS will just create a new variable and set it to missing. So all of your calculations will be done on those missing values.

 

Also you cannot overwrite the SASHELP datasets. They are READONLY.

data want;
  set sashelp.class;
  Weight = Weight - 1;
run;

 

 

tpage
Fluorite | Level 6

Is there any way I can do the same thing to the transposed data, using the _NAME_ and WEIGHT variables?

Tom
Super User Tom
Super User

It will be much header with the horizontal structure you will get from proc transpose.  

If you run your transpose step:

PROC TRANSPOSE
  data=sashelp.class
  OUT=class_transposed
; 
RUN;

You will have three observations that variables _NAME_ and COL1 to COL19 since there were 3 numeric variables and 19 observations in the original dataset.

So to subtract one from "wieght" you will need to do 19 subtractions. One for COL1 and one for COL2 etc.

You can use an ARRAY to make that easier to type.

data test;
  set class_transposed;
  array values col: ;
  if upcase(_name_)='WEIGHT' then do over values;
    values=values-1;
  end;
run;
PaigeMiller
Diamond | Level 26

@tpage wrote:

I am having trouble performing simple mathematical operations with SASHELP.class data. I am trying to subtract one pound from all of the classmates' weights, but an error message comes up reading "ERROR: User does not have appropriate authorization level for library SASHELP." Below is the code that I am currently using. I have also transposed the data, so I would like the results to be transposed as well.

 

 

PROC EXPORT data=sashelp.class
outfile=_dataout
dbms=dlm replace; run;

PROC CONTENTS data=sashelp.class; RUN;

PROC TRANSPOSE data=sashelp.class
OUT=class_transposed; RUN;

PROC REPORT data=class_transposed; RUN;

DATA sashelp.class;
set class_transposed;
Weight = Weight - 1;
RUN;

 

 

I also tried to perform the operation of subtracting one pound from all the weights in a data step with the variables "_NAME_" and "Weight" using IF THEN statements, but that didn't work either. 

 

Does anyone know how I can use data from sashelp and perform simple arithmetic operations without having the "authorization" error pop up? Thanks in advance.

 


You can't (it's not allowed) overwrite SASHELP.CLASS or any SAS data set in SASHELP. Thus, your last data step ought to be:

 

DATA class;
set class_transposed;
Weight = Weight - 1;
RUN;

This creates a temporary (WORK) data set, which is allowed.

 

By the way, the rest of the PROCs that you use don't seem to have anything to do with the stated goal of subtracting one from weight. Your entire program could be

 

data class;
    set sashelp.class;
    weight=weight-1;
run;

 

--
Paige Miller
tpage
Fluorite | Level 6

Do you know how I can perform the same arithmetic directly to the transposed data using the _NAME_ and Weight variables?

PaigeMiller
Diamond | Level 26

@tpage wrote:

Do you know how I can perform the same arithmetic directly to the transposed data using the _NAME_ and Weight variables?


Sure, but then the programming is much more difficult. So again I recommend that you don't bother with PROC TRANSPOSE.

--
Paige Miller

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 6 replies
  • 1583 views
  • 0 likes
  • 3 in conversation