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

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

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
  • 876 views
  • 2 likes
  • 3 in conversation