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?
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.
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.
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?
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!
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.