Help using Base SAS procedures

ISSUE - Variable and Condition

Not applicable
Posts: 0

ISSUE - Variable and Condition

Hello All

I am trying to create a variable "Known" and assign it a value of either 1 or 0 based on the Age and Income range for each ID.

Here is the data I have:
ID Age Income Known
001 23 2000 if (income = 2000 or 1500 or 3200) and if (age = 23 or age = 34) then 1 else 0.

I have about 1 million observations for the variable - ID and I have to generate a value for Known for each observation.

How would I be able to create a variable and assign a condition in the data statement?

Thanks for all your help.
Super Contributor
Super Contributor
Posts: 3,176

Re: ISSUE - Variable and Condition

Posted in reply to deleted_user
In a DATA step, use the SAS programming logic:


The SAS support website has a wealth of SAS product documentation resources and also supplemental technical and conference papers and sample code for specific topic points. Using the SEARCH facility, I found one such conference paper - link provided below:

A Hands-On Introduction to SAS® DATA Step Programming
Debbie Buck, D. B. & P. Associates, Houston, TX

Also, here is a SAS DOC link on DATA Step discussion:

DATA Step Processing

Scott Barry
SBBWorks, Inc.
Frequent Contributor
Posts: 77

Re: ISSUE - Variable and Condition

Posted in reply to deleted_user
Hi Pappu,

Here is an example of the code:

data income;
input ID $ Age Income;
if income in (2000,1500,3200) then do;
if age in (23,34) then Known=1;
else Known=0; end;
else Known=0;
001 23 2000
002 23 3000
003 34 3200
004 34 4000
005 24 2000
006 25 3000
007 38 1500
008 36 4000
proc print noobs;
title "Income and Age checked";
Not applicable
Posts: 0

Re: ISSUE - Variable and Condition

Posted in reply to statsplank
Thanks everybody!!!! It works
Ask a Question
Discussion stats
  • 3 replies
  • 3 in conversation