BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sumansparsh
Calcite | Level 5

How many times I can use and condition when I like to tag something.

for example:-

these are datasets follows:-

data lowl_high;
input loanid $ Gender$ Married$ Depender Education$ Self_employed$ Applicantincome Coapplicantincome Loanamount Loan_amount_term Credit_history Propertyarea$ ;
datalines;
LP001011 male Yes 0 Graduate No 5720 0 110 360 1 Urban
LP001012 female Yes 1 Graduate No 5730 0 112 372 2 SemiUrban
LP001013 female No 2 NonGraduate Yes 5740 1 114 380 3 Urban
LP001014 male No 0 Graduate No 5750 1 115 390 2 Semiurban
LP001015 female Yes 1 NonGraduate Yes 5760 0 116 400 1 Semiurban
LP001016 male No 0 Graduate Yes 5770 2 117 410 0 Urban
LP001017 female Yes 1 Graduate No 5780 1 118 420 1 Semiurban

 

but I am facing problem regarding this query:-

data Important9;
set Lowl_high;
Length Tag $15;
if Gender="female" and Married="Yes" and Education="Graduate" then Tag="High";
Else Tag="Low";
Run;

kindly help

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

I ran your code. It seems to work fine. Below is the log:

 

3178 data lowl_high;
3179 input loanid $ Gender$ Married$ Depender Education$ Self_employed$
3179! Applicantincome Coapplicantincome Loanamount Loan_amount_term
3179! Credit_history Propertyarea$ ;
3180 datalines;

NOTE: The data set WORK.LOWL_HIGH has 7 observations and 12 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.00 seconds


3188 ;
3189 data Important9;
3190 set Lowl_high;
3191 Length Tag $15;
3192 if Gender="female" and Married="Yes" and Education="Graduate" then
3192! Tag="High";
3193 Else Tag="Low";
3194 Run;

NOTE: There were 7 observations read from the data set WORK.LOWL_HIGH.
NOTE: The data set WORK.IMPORTANT9 has 7 observations and 13 variables.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds

 

Results:/*is this your expected result?*/

loanidGenderMarriedDependerEducationSelf_employedApplicantincomeCoapplicantincomeLoanamountLoan_amount_termCredit_historyPropertyareaTag
LP001011maleYes0GraduateNo572001103601UrbanLow
LP001012femaleYes1GraduateNo573001123722SemiUrbaHigh
LP001013femaleNo2NonGraduYes574011143803UrbanLow
LP001014maleNo0GraduateNo575011153902SemiurbaLow
LP001015femaleYes1NonGraduYes576001164001SemiurbaLow
LP001016maleNo0GraduateYes577021174100UrbanLow
LP001017femaleYes1GraduateNo578011184201SemiurbaHigh

View solution in original post

4 REPLIES 4
novinosrin
Tourmaline | Level 20

what is the problem? Please help understand the problem

sumansparsh
Calcite | Level 5
data Important9;
set Lowl_high;
Length Tag $15;
if Gender="female" and Married="Yes" and Education="Graduate" then Tag="High";
Else Tag="Low";
Run;
I can not get the result after run this syntax
actually I want to get result by three condition by using add,but I failed to do so
novinosrin
Tourmaline | Level 20

I ran your code. It seems to work fine. Below is the log:

 

3178 data lowl_high;
3179 input loanid $ Gender$ Married$ Depender Education$ Self_employed$
3179! Applicantincome Coapplicantincome Loanamount Loan_amount_term
3179! Credit_history Propertyarea$ ;
3180 datalines;

NOTE: The data set WORK.LOWL_HIGH has 7 observations and 12 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.00 seconds


3188 ;
3189 data Important9;
3190 set Lowl_high;
3191 Length Tag $15;
3192 if Gender="female" and Married="Yes" and Education="Graduate" then
3192! Tag="High";
3193 Else Tag="Low";
3194 Run;

NOTE: There were 7 observations read from the data set WORK.LOWL_HIGH.
NOTE: The data set WORK.IMPORTANT9 has 7 observations and 13 variables.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds

 

Results:/*is this your expected result?*/

loanidGenderMarriedDependerEducationSelf_employedApplicantincomeCoapplicantincomeLoanamountLoan_amount_termCredit_historyPropertyareaTag
LP001011maleYes0GraduateNo572001103601UrbanLow
LP001012femaleYes1GraduateNo573001123722SemiUrbaHigh
LP001013femaleNo2NonGraduYes574011143803UrbanLow
LP001014maleNo0GraduateNo575011153902SemiurbaLow
LP001015femaleYes1NonGraduYes576001164001SemiurbaLow
LP001016maleNo0GraduateYes577021174100UrbanLow
LP001017femaleYes1GraduateNo578011184201SemiurbaHigh
sumansparsh
Calcite | Level 5
Thank you so much

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 4 replies
  • 1058 views
  • 0 likes
  • 2 in conversation