Changing the Case of All Character Variables in a Data Set

This program will change the case for all of the character variables in a SAS data set. The key here is using the  _CHARACTER_ keyword in the ARRAY statement. This will create an array of all the character variables in the dataset.

Once the array is created, you can apply any character functions on all of the character variables.

data cars;
	set sashelp.cars;
	array Chars[*] _character_;

	do i=1 to dim(Chars);
		Chars[i]=upcase(Chars[i]);
	end;
	drop i;
run;

title "Listing the First 10 Observations in the Cars dataset";
proc print data=cars(obs=10 keep=_character_) noobs;
run;

Output:

Changing the Case of All Character Variables in a Data Set

Every week we'll send you SAS tips and in-depth tutorials

JOIN OUR COMMUNITY OF SAS Programmers!

Subhro Kar is an Analyst with over five years of experience. As a programmer specializing in SAS (Statistical Analysis System), Subhro also offers tutorials and guides on how to approach the coding language. His website, 9to5sas, offers students and new programmers useful easy-to-grasp resources to help them understand the fundamentals of SAS. Through this website, he shares his passion for programming while giving back to up-and-coming programmers in the field. Subhro’s mission is to offer quality tips, tricks, and lessons that give SAS beginners the skills they need to succeed.