BookmarkSubscribeRSS Feed
juliagoolia
Calcite | Level 5

Hello!

 

I have a variable field that has 8 slots for 8 optional answers (A-H).  They are not always in the same place, so I can't use substr.  

 

I basically need to select all individuals who have an 'A' anywhere in the variable.  Something like:

 

proc freq;

table var;

where var contains A;  (How do I say this in SAS?)

 

Thank you so much for any assistance!  I've been having trouble with the right search terms for google.

 

Julia

2 REPLIES 2
ballardw
Super User

The index function may be the easiest for single letters:

 

proc freq data=yourdata;
    table var;
   where index(var,'A') > 0;
run;

The Index function returns the position, number of character in the string, as an integer if found or zero if not found. The first parameter is what to search and the second parameter is what you  search for. This is case sensitive and would not find 'a' when searching for 'A'.

tarheel13
Rhodochrosite | Level 12

you can also use prxmatch

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

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 838 views
  • 2 likes
  • 3 in conversation