DATA Step, Macro, Functions and more

Case insensitive in PROC MEANS

Accepted Solution Solved
Reply
PROC Star
Posts: 748
Accepted Solution

Case insensitive in PROC MEANS

Hi guys.. A very simple example below, where I create some test data such that Origin has both the character values Europe and EUROPE. 

 

data test;
   set sashelp.cars;
   if type = 'Sedan' and Origin = 'Europe' then Origin = 'EUROPE';
run;

proc means data = test;
   class Origin;
   var Weight;
run;

When I run the proc means, can I make SAS interpret the class variable case insensitive?

 

Regards


Accepted Solutions
Solution
‎12-21-2016 03:59 AM
SAS Super FREQ
Posts: 3,753

Re: Case insensitive in PROC MEANS

Yes. In general you can define a SAS format that collapses all of the possible choices into a single formatted value.

 

For your example, you don't need to create a custom format because the $UPCASE. format converts all values to uppercase:

 

proc means data = test;
format Origin $UPCASE.;
   class Origin;
   var Weight;
run;

View solution in original post


All Replies
Super User
Super User
Posts: 7,955

Re: Case insensitive in PROC MEANS

Well, in my opinion, this is a data modelling question rather than a coding one.  What you want to end up with is a dataset contianing consistent data.  Generally I like to see a dataset where textual elements contain a code as well, so in the one below you would have a step which codes all possible combinations of data element xyz to a consitent manner (be that a number or shortened code text.

So, you would code your country column based on given rules such as country in (upcase()=EUROPE, EUR, EU) all equal 1 (or EU or something).

As for your question, not sure how you would make a procedure know all the connotations of the data which only you know.  As above, you state Europe=EUROPE, but what about EU which is another common abbreviation.  

Solution
‎12-21-2016 03:59 AM
SAS Super FREQ
Posts: 3,753

Re: Case insensitive in PROC MEANS

Yes. In general you can define a SAS format that collapses all of the possible choices into a single formatted value.

 

For your example, you don't need to create a custom format because the $UPCASE. format converts all values to uppercase:

 

proc means data = test;
format Origin $UPCASE.;
   class Origin;
   var Weight;
run;
PROC Star
Posts: 748

Re: Case insensitive in PROC MEANS

Thank you all for your advice and happy holidays Smiley Happy

☑ This topic is solved.

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

Discussion stats
  • 3 replies
  • 223 views
  • 4 likes
  • 3 in conversation