BookmarkSubscribeRSS Feed
Fol_
Calcite | Level 5

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

7 REPLIES 7
Haikuo
Onyx | Level 15

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

Fol_
Calcite | Level 5

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.

LinusH
Tourmaline | Level 20

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
Fol_
Calcite | Level 5

Thanks!

Tom
Super User Tom
Super User

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.

Fol_
Calcite | Level 5

Thanks!

Ksharp
Super User

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

sas-innovate-2024.png

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.

 

Register now!

What is Bayesian Analysis?

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 7 replies
  • 1875 views
  • 4 likes
  • 5 in conversation