BookmarkSubscribeRSS Feed
Grandhi4
Calcite | Level 5

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

7 REPLIES 7
Keith
Obsidian | Level 7

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

Grandhi4
Calcite | Level 5

Yes

shivas
Pyrite | Level 9

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

Grandhi4
Calcite | Level 5

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

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

art297
Opal | Level 21

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;

kuridisanjeev
Quartz | Level 8

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

art297
Opal | Level 21

: 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;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 935 views
  • 1 like
  • 5 in conversation