propcase

Reply
Frequent Contributor
Posts: 86

propcase

Hi,

Ex:- In one variable i have like this 

Input  DEVELOPING COUNTRY INDIA       i want it like this 'Developing Country      INDIA'

Input  DEVELOPING COUNTRY RUSSIA      i want it like this 'Developing Country      RUSSIA'

Like this I have 2000 records...

Thanks

Smiley Happy

Regular Contributor
Posts: 151

Re: propcase

is it always the last word that needs to stay capitalised?

Frequent Contributor
Posts: 86

Re: propcase

Yes

Super Contributor
Posts: 349

Re: propcase

Hi,

Try this...

data have;

input name $ 30.;

var_New=propcase(substr(name,1,19))||upcase(scan(name,3));

cards;

DEVELOPING COUNTRY INDIA

DEVELOPING COUNTRY RUSSIA

DEVELOPING COUNTRY CANADA

DEVELOPING COUNTRY china

;

run;

Thanks,

Shiva

Frequent Contributor
Posts: 86

Re: propcase

Thanks Shiva But is there any code for selecting 'Words' ?

Because if i given 1, 19...If below the record has less characters...

PROC Star
Posts: 7,366

Re: propcase

How about something like:

data have;

  length name var_new $30;

  input name &;

  do _n_=1 to countw(name)-1;

    var_New=catx(" ",var_New,propcase(scan(name,_n_)));

  end;

  var_New=catx(" ",var_New,upcase(scan(name,_n_)));

cards;

DEVELOPING COUNTRY INDIA

DEVELOPING COUNTRY RUSSIA

DEVELOPING COUNTRY CANADA

DEVELOPING COUNTRY china

;

run;

Super Contributor
Posts: 276

Re: propcase

Hi Art..

Great logic..it is working perfectly.

I want to know one more logic(Actually it is not my requirement but i am curious to get the logic)...

If i want to display "DEVELOPING" word as "DeVeLoPiNg" ..how can we change the above logic..

(Please Don't mind if i am  asking useless question:-))..

Regards..

sanjeev.K

PROC Star
Posts: 7,366

Re: propcase

: You can manipulate data with whatever functions and logic are needed and available.  E.g., while I'm not sure exactly which parts you are trying to change, but the following should give you a clue as to some of the possibilities:

\

data have (drop=j alternate);

  length name var_new alternate alternate_New $30;

  input name &;

  do _n_=1 to countw(name)-1;

    var_New=catx(" ",var_New,propcase(scan(name,_n_)));

    alternate=upcase(scan(name,_n_));

    do j=2 to length(scan(name,_n_)) by 2;

      substr(alternate,j,1)=lowcase(substr(alternate,j,1));

    end;

    alternate_New=catx(" ",alternate_New,alternate);

  end;

  var_New=catx(" ",var_New,upcase(scan(name,_n_)));

  alternate_New=catx(" ",alternate_New,upcase(scan(name,_n_)));

  cards;

DEVELOPING COUNTRY INDIA

DEVELOPING COUNTRY RUSSIA

DEVELOPING COUNTRY CANADA

DEVELOPING COUNTRY china

;

run;

Ask a Question
Discussion stats
  • 7 replies
  • 443 views
  • 1 like
  • 5 in conversation