SAS : WildCard Character

Live Online Training : SAS Programming with 50+ Case Studies

- Explain Programming Concepts in Simple English
- Live Projects
- Scenario Based Questions
- Job Placement Assistance
- Get 20% off till July 14, 2017

In this tutorial, you will learn how to use wildcard character in SAS.

Example 1 : Keep all the variables start with 'X'

DATA READIN;
INPUT ID X1 X_T $;
CARDS;
2 3 01
3 4 010
4 5 022
5 6 021
6 7 032
;
RUN;
DATA READIN2;
SET READIN (KEEP = X:);
RUN;

The COLON (:) tells SAS to select all the variables starting with the character 'X'.

Example 2 : Subset data using wildcard character
DATA READIN2;
SET READIN;
IF X_T =: '01';
RUN;
In this case, the COLON (:) tells SAS to select all the cases starting with the character '01'.

Example 3 : Use of WildCard in IN Operator
DATA READIN2;
SET READIN;
IF X_T IN: ('01', '02');
RUN;
In this case, the COLON (:) tells SAS to select all the cases starting with the character '01' and '02'.

Example 4 : Use of WildCard in GT LT (> <) Operators
DATA READIN2;
SET READIN;
IF X_T >: '01';
RUN;
In this case, the COLON (:) tells SAS to select all the cases from character '01' up alphabetically.

Example 5 : WildCard in Function
data example3;
set temp2;
total =sum(of height:);
run;

Example 6 : WildCard in Array
proc sort data = sashelp.class out=class;
by name sex;
run;

proc transpose data = sashelp.class out=temp;
by name sex;
var height weight;
run;

proc transpose data = temp delimeter=_ out=temp2(drop=_name_);
by name;
var col1;
id _name_ sex;
run;

proc sql noprint;
select CATS('new_',name) into: newnames separated by " "
from dictionary.columns
where libname = "WORK" and memname = "TEMP2" and name like "Height_%";
quit;

data temp2;
set temp2;
array h(*) height:;
array newh(*) &newnames.;
do i = 1 to dim(h);
newh{i} = h{i}*2;
end;
drop i;
run;

SAS Tutorials : 100 Free SAS Tutorials

About Author:

Deepanshu founded ListenData with a simple objective - Make analytics easy to understand and follow. He has close to 7 years of experience in data science and predictive modeling. During his tenure, he has worked with global clients in various domains like retail and commercial banking, Telecom, HR and Automotive.


While I love having friends who agree, I only learn from those who don't.

Let's Get Connected: Email | LinkedIn

Get Free Email Updates :
*Please confirm your email address by clicking on the link sent to your Email*

Related Posts:

5 Responses to "SAS : WildCard Character"

  1. Thank You Deepanshu, This Is great! Very Efficient!

    ReplyDelete
  2. In the example 6 in the last SQL step in the WHERE clause must be upcase(name) like "height_%"; (or use "Height_%").

    ReplyDelete
    Replies
    1. Did you mean lowcase(name) like "height_%"?

      Delete
  3. Hello ,

    Can you please explain Example 6 : WildCard in Array concept in detail?

    ReplyDelete
  4. This comment has been removed by the author.

    ReplyDelete

Next → ← Prev