BookmarkSubscribeRSS Feed
bradklassen
Calcite | Level 5

Hi,

 

I am having a problem renaming columns with capitals. SAS will only capitalize the variables that are different on the left and right of the equal signs. I would like to rename a variable exactly the same just with capitals. Ex. I would like run_number to become Run_Number. However, SAS will not recognize the command and leave the variable name as run_number.

 

I have provided the code below.

 

data temp.GPS_Edit5 (rename =(lightbeam=_Lightbeam run_number=Run_Number last_name=Last_Name first_name=First_Name
       discipline=Discipline distance_m=_Distance_m speed_kmh=_Speed_km_h roll_angle=_Roll_angle lightbeam_time_s=_LB_time_s           corr_z=Corr_z));
set temp.GPS_Edit4;
run;

 

Thanks!

6 REPLIES 6
Kurt_Bremser
Super User

What for? For code, run_number and Run_number are 100 % equal.

If you want to have something nice to read, put in in a label.

 

Allowing upper- and lowercase without making the whole language case-sensitive is one of the blunders SAS has committed over the years, IMO.

C, C++, C#, Java, Python, Go, Ruby are all case sensitive.

bradklassen
Calcite | Level 5

I would like it in that format for the purpose of exporting it to Tableau. I already have some tableau calculated fields created that reference Run_Number rather than run_number. Tableau will not identify that they are supposed to be the same columns.

Kurt_Bremser
Super User

@bradklassen wrote:

I would like it in that format for the purpose of exporting it to Tableau. I already have some tableau calculated fields created that reference Run_Number rather than run_number. Tableau will not identify that they are supposed to be the same columns.


Oh yes. See the second part of my previous post.

OTOH, SQL and PL/1 (on which the data step language is modeled) are also case insensitive.

Tom
Super User Tom
Super User

Did you try renaming on the way in instead of on the way out?

data have;
  run_number=1;
  length name $32 ;
  name=vnamex('run_number');
  put (_all_) (=);
run;
data want ;
  set have(rename=(run_number=Run_Number));
  name=vnamex('run_number');
  put (_all_) (=);
run;
296  data have;
297    run_number=1;
298    length name $32 ;
299    name=vnamex('run_number');
300    put (_all_) (=);
301  run;

run_number=1 name=run_number
NOTE: The data set WORK.HAVE has 1 observations and 2 variables.


302  data want ;
303    set have(rename=(run_number=Run_Number));
304    name=vnamex('run_number');
305    put (_all_) (=);
306  run;

Run_Number=1 name=Run_Number
NOTE: There were 1 observations read from the data set WORK.HAVE.
NOTE: The data set WORK.WANT has 1 observations and 2 variables.
VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

I agree with @Kurt_Bremser use labels that is why SAS has labels, so you can see the names without the underscores and uppercase.

 those labels also help those who don't know the data putting the Caps in here and there will not assist in the final outcome.

Use the right tool for the job.

 

FreelanceReinh
Jade | Level 19

Hi @bradklassen,

 

If you only rename variables, you don't need to read the data with a SET statement, which can be time-consuming for a large dataset. It's more efficient to use PROC DATASETS.

 

Example:

data GPS_Edit4;
run_number=1;
corr_z=2;
speed_kmh=3;
run;

proc datasets lib=work nolist; /* in your case: lib=temp */
modify GPS_Edit4;
rename run_number=Run_Number corr_z=Corr_z speed_kmh=_Speed_km_h;
quit;

 

If you need the SET statement anyway, you can use the RETAIN statement (before the SET statement) and thus shorten the RENAME= dataset option:

data GPS_Edit5;
retain Run_Number Corr_z;
set GPS_Edit4(rename=(speed_kmh=_Speed_km_h));
* ... more statements ...;
run;

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 6 replies
  • 3991 views
  • 5 likes
  • 5 in conversation