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


data cars_subset;
set sashelp.cars;
where upcase(drivetrain)="FRONT";
RUN;

data cars_subset;
set sashelp.cars;
where drivetrain=upcase("front");
RUN;

 

first one produces 226 obs and 15 columns

and second one produces 0 obs and 15 columns

 

 

why it produces two different results ??

and please brief me about how upcase function works like this situation?

1 ACCEPTED SOLUTION

Accepted Solutions
ErikLund_Jensen
Rhodochrosite | Level 12

Hi @Karim18 

 

The value of the variable DRIVETRAIN in the CLASS data set is "Front".

If you upcase the variable value the result is "FRONT", so the first comparison is true.

But in the second comparison the original variable value "Front" is compared to upcase("front"), also ti "FRONT", which is false.

View solution in original post

4 REPLIES 4
ErikLund_Jensen
Rhodochrosite | Level 12

Hi @Karim18 

 

The value of the variable DRIVETRAIN in the CLASS data set is "Front".

If you upcase the variable value the result is "FRONT", so the first comparison is true.

But in the second comparison the original variable value "Front" is compared to upcase("front"), also ti "FRONT", which is false.

Karim18
Calcite | Level 5
sir upcase function manipulates data in execution phase and where statemt is compiled time statement



then how come it changes to uppercase???
Reeza
Super User
Timing of when something happens doesn't matter in this particular situation, it has to do with the values not matching.
Reeza
Super User

Your first set of code:

where upcase(drivetrain)="FRONT";

Note that DRIVETRAIN and FRONT are both upcased in this filter.

 

Your second set of code:

where drivetrain=upcase("front");

In this one FRONT is upcased but we don't know if DRIVETRAIN is, unless it was done previously. Given the results, it seems like it's not upcased so both sides of your equal signs are not the same. You could be comparing "Front" to "FRONT" which will not match.

 


@Karim18 wrote:


data cars_subset;
set sashelp.cars;
where upcase(drivetrain)="FRONT";
RUN;

data cars_subset;
set sashelp.cars;
where drivetrain=upcase("front");
RUN;

 

first one produces 226 obs and 15 columns

and second one produces 0 obs and 15 columns

 

 

why it produces two different results ??

and please brief me about how upcase function works like this situation?


 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 4 replies
  • 594 views
  • 1 like
  • 3 in conversation