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?


 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1035 views
  • 1 like
  • 3 in conversation