I have more than 400 variables in my dataset with mixed case (some upper and some lower). I want to change all of them to lowercase. I tried following but doesn't work. Can someone please help?
array vars(*) _character_;
do i=1 to dim(vars);
Subsequent to this, I run some models in STATA which is case sensitive.
So far I was using SAS Enterprise 4.3 but recently shifted to SAS 7.1 and am wondering if something has changed.
I assume you mean Enterprise Guide 7.1? I doubt anyone ever ran SAS version 7.1 as version 7 was quickly replaced with version 8 and that was, what 20 years ago?
You can try just try setting validvarname option to UPCASE.
Explain "doesnt work". Supply example data that illustrates the issue when your code is run on it.
The following does what you ask for a copy of the data set SASHELP.CLASS that you should have available to test on.
It creates a control data set to get the names of the varaibles in the data set and make an uppercase version. Then uses that set to create Proc Datasets code to change the names of the variable in the Work.Class copy.
The where clause in the Proc Sql requires uppercase library and memname values of the set you want to modify. I have included two Proc contents steps to show the before and after names of the variables.
proc sql noprint; create table work.namechange as select name, upcase(name) as newname from dictionary.columns where libname='SASHELP' and Memname='CLASS' ; quit; data work.class; set sashelp.class; run; proc contents data=work.class;run; data _null_; set work.namechange end=last; if _n_=1 then call execute("proc datasets library=work nodetails; modify class; rename "); call execute( name|| '='|| newname); if last then call execute('; run;quit;'); run; proc contents data=work.class;run;
Depending on how you export the data for STATA use you likely have other options.
Here another coding option which writes the executed statements in a nice way into the SAS log.
%macro upcaseVarnames(lrefTbl); %local lref tbl; %let lref=%upcase(%scan(work.&lrefTbl,-2,.)); %let tbl=%upcase(%scan(&lrefTbl,-1,.)); filename codegen temp; data _null_; file codegen; /* file print;*/ length _cmd $65; set sashelp.vcolumn(where=(libname="&lref" and memname="&tbl")) end=_last; if _n_=1 then do; put "proc datasets lib=&lref nolist;" / " modify &tbl;" / " rename" ; end; _cmd=cats(name,'=',upcase(name)); put " " _cmd; if _last then do; put " ;" / " run;" / " contents data=&tbl;" / " run;" / "quit;" ; end; run; %include codegen / source2; filename codegen clear; %mend; data sample sample2; set sashelp.class; run; %upcaseVarnames(sample) %upcaseVarnames(sample2)
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.