Hi,
I have a column - city within a dataset that displays the city a client lives. But some cities are recorded in upper case , some in lower case and some in mixed case so when i try to run the frequency on cities, the same city is counted twice if recorded in different cases for example, london may be recorded as :
LONDON
london
Londnon
lonDON
so what statement can i use to change all the example to just one city in Uppercase i.e LONDON within the data set?
Thanks
Exactly, just use upcase() to convert your variable to upper case. Such as:
data have;
input city $;
cards;
LONDON
london
Londnon
lonDON
;
data want;
set have;
city=upcase(city);
run;
proc print;run;
Regards,
Haikuo
Thanks Haikuo,
But london is not the only city that was just an example . I have hundreds of cities in the data set, it actually contains about 100 000 records, so i may not be able to use the CARDS statement.
The cards statement just represents some sample data just to describe this example.
Just replace have in the second step to whatever table you already got data in, and skip step 1.
Thanks!
If you just want to use PROC FREQ on the variable then use the $UPCASE function.
proc freq data=have;
tables city;
format city $upcase.;
run;
If you want to fix the data then use the upcase() function in a data step as Haikuo as pointed out.
Thanks!
Here is a simple way which can change all alpha character into UPPERCASE.
filename tran 'c:\temp.dat'; proc cport data=sashelp.class file=tran outtype=upcase; run; proc cimport infile=tran data=want; run;
Ksharp
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.