Help using Base SAS procedures

ISSUE - Variable and Condition

Reply
N/A
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.
P
Super Contributor
Super Contributor
Posts: 3,174

Re: ISSUE - Variable and Condition

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

IF THEN ;


The SAS support http://support.sas.com/ 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
http://www2.sas.com/proceedings/sugi30/134-30.pdf


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

DATA Step Processing
http://support.sas.com/documentation/cdl/en/lrcon/61722/HTML/default/a001281588.htm


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;
datalines;
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";
run;
N/A
Posts: 0

Re: ISSUE - Variable and Condition

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