Desktop productivity for business analysts and programmers

using upcase

Accepted Solution Solved
Reply
Regular Contributor
Posts: 220
Accepted Solution

using upcase

Hi guys i am using sas eg 5.1 and i have one dataset name "data1" (50 obs), in "data1" have one variable name "empname" and all values for "empname" are in lower case. I want to change both variable name "empname" and all values in upcase. how can i do that?

please help!

thanks.


Accepted Solutions
Solution
‎03-20-2013 06:09 PM
Super Contributor
Posts: 1,636

Re: using upcase

data have;

input empname $;

cards;

abc

bbv

cvb

;

data want;

  set have(rename=empname=EMPNAME);

  empname=upcase(empname);

proc print;run;

                               Obs    EMPNAME

                                   1       ABC

                                   2       BBV

                                   3       CVB

View solution in original post


All Replies
Solution
‎03-20-2013 06:09 PM
Super Contributor
Posts: 1,636

Re: using upcase

data have;

input empname $;

cards;

abc

bbv

cvb

;

data want;

  set have(rename=empname=EMPNAME);

  empname=upcase(empname);

proc print;run;

                               Obs    EMPNAME

                                   1       ABC

                                   2       BBV

                                   3       CVB

Regular Contributor
Posts: 220

Re: using upcase

Hi Linlin, i got one issue in my dataset. your code works perfect but i have more than one empname value in dataset. what i need to change for that?

eg;

empname

abc

abc

abc

bbv

bbv

cvb

cvb

cvb

cvb


Thanks.

Super User
Posts: 19,170

Re: using upcase

What do you mean you have more than one empname? More than one variable?

The fomula will work on the entire column, so all observations of one variable.

Regular Contributor
Posts: 220

Re: using upcase

no, i mean more than one value for variable;

eg;

empname

abc

abc

abc

bbv

bbv

cvb

cvb

cvb

cvb

Super User
Posts: 19,170

Re: using upcase

LinLin's code should work regardless.

If it doesn't, post the code you used and the log, with a print of the output that doesn't work.

Regular Contributor
Posts: 220

Re: using upcase

so if i have value ABC 50 times (for variable empname) in dataset then i have to mention it 50 times in card - is that right?

Super User
Posts: 19,170

Re: using upcase

Mention what 50 times? ABC or the upcase function?

Note LinLin's code thoroughly. She first imports the data AS IS. A second datastep converts the empname to upcase, and a second dataset is created.

Regular Contributor
Posts: 220

Re: using upcase

50 times ABC...

EMPNAME

ABC

ABC

ABC

.

.
.

ABC

Super User
Posts: 5,369

Re: using upcase

Sandy,

It's time for a break.  You've been working too hard.

If you wanted to assign X=1, you would just add the statement:

data want;

set have;

X=1;

run;

You wouldn't have to add it 50 times, just because you have 50 observations in your data set.  Similarly, you could code:

data want;

set have;

empname = upcase(empname);

run;

It changes EMPNAME for every observation in your data set.  You don't need to know how many observations you have, or what the values of EMPNAME are.  The statement just executes for every observation.

Super User
Posts: 19,170

Re: using upcase

In QueryBuilder add a computed column.

Use the function upper or upcase to create a new variable that is upcase.

Regular Contributor
Posts: 220

Re: using upcase

Thanks Linlin and Reeza...appreciate your help.

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 11 replies
  • 416 views
  • 0 likes
  • 4 in conversation