Help using Base SAS procedures

Change case of variable name

Accepted Solution Solved
Reply
New Contributor
Posts: 2
Accepted Solution

Change case of variable name

Is there a way to change the letters in a variable name from uppercase to lowercase?

Thank you!


Accepted Solutions
Solution
‎01-26-2012 06:39 PM
Contributor
Posts: 43

Change case of variable name

Use the RENAME statement in PROC DATASETS (avoiding recreating the data set):

data have;
  myvar = 0;
run;

data _null_;
  set have;
  put _all_;
run;

proc datasets lib=work nolist;
  modify have;
     rename myvar=MYVAR;
run;
quit;

data _null_;
  set have;
  put _all_;
run;

View solution in original post


All Replies
PROC Star
Posts: 7,363

Change case of variable name

Never did it!  However, rename in a datastep should work (e.g., UNTESTEDSmiley Happy

data sashelp.class;

  set sashelp.class(rename=(name=NAME));

run;

I can't test it at the moment, but I would think that the lowcase, upcase and propcase functions could be used as well.  e.g.,

data sashelp.class;

  set sashelp.class(rename=(name=upcase(NAME)));

run;

Regular Contributor
Posts: 184

Re: Change case of variable name

I think you need %SYSFUNC, as in

data have ;

myvar = 0 ;

run ;

data want ;

set have(rename=(myvar=%sysfunc(upcase(myvar))));

put _all_ ;

run;

Senior User
Posts: 1

Re: Change case of variable name

%let per = %sysfunc(lowcase(&period));
%put &per;
feb2017

With this I can now read/email sas datasets. filename_@per.sas7bdat files in UNIX/LINUX !!! Yey!!!
Solution
‎01-26-2012 06:39 PM
Contributor
Posts: 43

Change case of variable name

Use the RENAME statement in PROC DATASETS (avoiding recreating the data set):

data have;
  myvar = 0;
run;

data _null_;
  set have;
  put _all_;
run;

proc datasets lib=work nolist;
  modify have;
     rename myvar=MYVAR;
run;
quit;

data _null_;
  set have;
  put _all_;
run;

New Contributor
Posts: 2

Change case of variable name

Thanks Bob, this worked well!

Super Contributor
Posts: 1,636

Change case of variable name

How about:

data have;

input (AA  BB  cc) ($);

cards;

qw er ty

cd rt ty

;

proc print;run;

proc sql noprint;

select catx('=',name,lowcase(name)) into : names separated by ' '

  from dictionary.columns

    where libname='WORK' and memname='HAVE';

quit;

proc datasets lib=work nolist;

modify have;

rename &names;

run;

quit;

proc print;run;

Linlin

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 7223 views
  • 1 like
  • 6 in conversation