Help using Base SAS procedures

Proc for changing case

Reply
Occasional Contributor
Posts: 11

Proc for changing case

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

Respected Advisor
Posts: 3,124

Proc for changing case

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

Occasional Contributor
Posts: 11

Proc for changing case

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.

Super User
Posts: 5,256

Proc for changing case

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.

Data never sleeps
Occasional Contributor
Posts: 11

Proc for changing case

Thanks!

Super User
Super User
Posts: 6,500

Proc for changing case

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.

Occasional Contributor
Posts: 11

Proc for changing case

Thanks!

Super User
Posts: 9,681

Proc for changing case

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

Ask a Question
Discussion stats
  • 7 replies
  • 210 views
  • 3 likes
  • 5 in conversation