BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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
3 REPLIES 3
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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.
statsplank
Calcite | Level 5
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;
deleted_user
Not applicable
Thanks everybody!!!! It works

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1301 views
  • 0 likes
  • 3 in conversation