BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sas_9
Obsidian | Level 7

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Linlin
Lapis Lazuli | Level 10

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

11 REPLIES 11
Linlin
Lapis Lazuli | Level 10

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

sas_9
Obsidian | Level 7

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.

Reeza
Super User

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.

sas_9
Obsidian | Level 7

no, i mean more than one value for variable;

eg;

empname

abc

abc

abc

bbv

bbv

cvb

cvb

cvb

cvb

Reeza
Super User

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.

sas_9
Obsidian | Level 7

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?

Reeza
Super User

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.

sas_9
Obsidian | Level 7

50 times ABC...

EMPNAME

ABC

ABC

ABC

.

.
.

ABC

Astounding
PROC Star

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.

Reeza
Super User

In QueryBuilder add a computed column.

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

sas_9
Obsidian | Level 7

Thanks Linlin and Reeza...appreciate your help.

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!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 11 replies
  • 2126 views
  • 0 likes
  • 4 in conversation